Search⌘ K
AI Features

Solution Review: Testing in PostgreSQL

Explore how to write unit tests for PostgreSQL databases by using pg_prove for automated testing. Understand how to check the existence of tables and columns with has_table and has_column functions combined with transactional testing in SQL.

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:

XML
su - postgres -c 'pg_prove -h 0.0.0.0 -d "mydb" -U "postgres" /usercode/tests/*.sql'

Click the “Run” button in the following ...