Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Samuel Nitsche
Samuel Nitsche

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

  1. Avoid duplication where possible
  2. Give some context about dependencies between topics/modules
  3. Reduce the time my tests need to run

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Curiosity-driven software-developer, 10x underpants.Striving for harm-reduction.We don't need more rockstars, we need more mentors.
  • Location
    Germany
  • Work
    Software Developer at Smart Enterprise Solutions GmbH
  • Joined

More fromSamuel Nitsche

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp