mercredi 28 juin 2017

Nesting or grouping tests in pgTAP

I recently started working on a project that uses pgtap for testing custom plpgsql functions. To write cleaner test with a more readable output, I was wondering if it is possible to nest or group tests. What I'm looking for, is an output similar the following:

       with this configuration
ok 1 -   it can do task 1
ok 2 -   it can do task 2
       with other configuration
ok 3 -   it can do task 3
ok 4 -   it can do task 4

The configuration could be variables, that are shared between the individual test, or just properties, that the queries in the tasks have in common. I know this nesting and grouping from other test suites like RSpec and always found it quite useful, since the output is very descriptive and readable.

What I'm doing at the moment to at mimic the desired output, is adding pass() tests and manually indent the description strings, as seen below. This works but is not ideal in my opinion, since it increases the number of tests.

PREPARE shared_want AS some_query;

SELECT pass('with this configuration');

PREPARE task1_have AS some_query;
SELECT results_eq('task1_have',
                  'shared_want',
                  '  it can do task 1');

PREPARE task2_have AS some_query;
SELECT results_eq('task2_have',
                  'shared_want',
                  '  it can do task 2');

Is there a way to accomplish this in a better way?

Thanks, Felix

Aucun commentaire:

Enregistrer un commentaire