Solution Review: Testing in PostgreSQL
See a detailed analysis of the solution to the "Testing in SQL" challenge.
We'll cover the following...
Here is the solution for the challenge of writing a test script for unit testing and running your test using pg_prove
.
Solution
The tests are written in the respective files. The table required for the challenge is already created for you.
Use the following command to run the tests:
Press + to interact
su - postgres -c 'pg_prove -h 0.0.0.0 -d "mydb" -U "postgres" /usercode/tests/*.sql'
Click the “Run” button in the following widget to start.
-- Load the TAP functions. BEGIN; -- Plan the tests. SELECT plan(1); -- Run the tests. SELECT has_table('foo'); -- Finish the tests and clean up. SELECT * FROM finish(); ROLLBACK;
Running test script for unit testing
...