Posted on • Originally published atcleandatabase.wordpress.com on
#100CodeExamples – utPLSQL’s Suite Hierarchy in action
utPLSQL gives you the possibility to organize test-suites in a hierarchical way. We can use this for collecting setup-/cleanup-methods into separate parent-packages.
We can not only outsource our setup-methods into a single place (following DRY principle), but we can also make clear that several test-suites are somehow connected.
createtableplanets(idintegerprimarykey,namevarchar(256));createorreplacepackageut_planet_setupas-- %suite(planetSetup)-- %suitepath(galaxy)-- %beforeallproceduresetup_test_planet;end;/createorreplacepackagebodyut_planet_setupasproceduresetup_test_planetasbegininsertintoplanets(id,name)values(-1,'Korriban');end;end;/createorreplacepackageut_planetsas-- %suite(Planets)/* Hierarchic Suitepath must contain any parent suitepaths and the name of the parent test-package */-- %suitepath(galaxy.ut_planet_setup)-- %test(Check if test-plantes exist: 1 planet)proceduretest_planets_exist;end;/createorreplacepackagebodyut_planetsasproceduretest_planets_existasl_countint;beginselectcount(*)intol_countfromplanetswhereid<0;ut.expect(l_count).to_equal(1);end;end;/createorreplacepackageut_garrisonsas-- %suite(Garrisons)-- %suitepath(galaxy.ut_planet_setup)-- %beforeallproceduresetup_another_test_planet;-- %test(Check if test-plantes exist: 2 planets)proceduretest_planets_exist;/* We could add some more tests for Planet-Garrisons here */end;/createorreplacepackagebodyut_garrisonsasproceduresetup_another_test_planetasbegininsertintoplanets(id,name)values(-2,'Dromund Kaas');end;proceduretest_planets_existasl_countint;beginselectcount(*)intol_countfromplanetswhereid<0;ut.expect(l_count).to_equal(2);end;end;/
When we run the suite by its suitepath, the parent suite-name is shown with its displayname but has to be called by its package-name. A beginning ":" means we search for a suitepath:
callut.run(':galaxy.ut_planet_setup');
galaxy planetSetup Planets Check if test-plantes exist: 1 planet [,011 sec] Garrisons Check if test-plantes exist: 2 planets (,003 sec) Finished in ,020764 seconds 2 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)
If we call it by package-name only, utPLSQL doesnt run the child suites
callut.run('ut_planet_setup');
galaxy planetSetup Finished in ,03545 seconds 0 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)
But we can call it with either of the specific test suites names for a partial test:
callut.run('ut_planets');callut.run('ut_garrisons');
galaxy planetSetup Planets Check if test-plantes exist: 1 planet (,001 sec) Finished in ,02547 seconds 1 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)galaxy planetSetup Garrisons Check if test-plantes exist: 2 planet (,001 sec) Finished in ,01228 seconds 1 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)
You can find a full example atgithub.
Why I learned this
I try to clean up my test codebase and
- Avoid duplication where possible
- Give some context about dependencies between topics/modules
- Reduce the time my tests need to run
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse