pg_regress is a utility to run the regression testcases. This utility is available from the PG source code repository - reside under regress/ folder . From the Development point of view - Regression testing plays a very important role .No developer would like to see adding 1 feature - breaks 10 others things or fixing 1 bug -introducing 10 more bugs.
How it works -One thing which is mandatory before we run pg_regress i.e sql file(which contain all sql queries).
Lets assume we have a feature to test whether arithmetic operator - lets say "+" is working fine with simple select query or not .
First thing -We need to do is testing .These below are the sql statements which we would like to add in the testcase file in regression testsuite to make sure - Adding new other feature or changing the existing code later should not hamper the functionality of the feature for which the testcases has been added in the testcase suite. if it is so then testcase will start failing and we can catch the regression easily before complaint comes in from end user after release the software.
Assuming all the above results is valid . To make this as part of regression testsuite so that it can be run via pg_regress everyday/at the development phase - We can add sql statements in either any pre-existing sql files or create a new sql file -whichever is more appropriate .
Here creating a new sql file with the name - test.sql . SQL file extension should be ".sql"
Now, We can generate corresponding expected file by either running pg_regress or psql against this sql file . Using psql to generate the o/p file . Output file extension should be ".out"
pg_regress can be run against a running PG Server or it can initialise cluster its own before executing the sql file. Like Football - Placement is very important of sql/out file so make sure - test.sql file location is as same as test.out file location - the only difference is -.sql file will go under sql/ directory whereas .out file will go under expected/ directory otherwise pg_regress will throw an error i.e file not found.
In this case - Creating a directory called -mydir under sql/ directory and same under expected/ directory and copying test.sql and test.out file there.
Case 1 - Run pg_regress against running PG Server and without schedule file
Case 2:- Run pg_regress using option --temp-instance (which will initialise temporary instance its own) -thats mean - no pre-running server is needed before executing test cases.
Now, We need to add the testcase in schedule file so that it can be part of regression testsuite , We can either create a new schedule file OR add the testcase file name in pre-existing schedule file i.e serial_schedule OR parallel_schedule which we are having under regress/ folder
In this case- Adding the testcase file in serial_schedule file
Run the schedule file using pg_regress
Testcase is passing and also part of regression testsuite(locally i.e in local repo).
Hope this was helpful !
No comments:
Post a Comment