How to define setup/teardown for suites / run sessions with munit ?
MUnit tests often requires time consuming preparation ( e.g. starting an application, create design), which not all test cases want to do each time in their setup. Same situation exist for cleanups ( close applications, delete designs) and test case teardown.
Other frameworks like pytest allows to define not only for the test itself a setup / teardown, even for suites and run sessions pytest - Fixture scopes
Question is, which concept has MUnit for this?
Checking the one_time_set_up() and one_time_tear_down() functions shows, that these steps are not executed in each run. It requires that a run with other test classes are executed before or afterwards.
- one_time_tear_down() is only executed, when another test class is running afterwards
- one_time_set_up() is only executed, when another test class is running afterwards
- sample code see one_time_munit_samples.magik
MagikSF> one_time_munit_sample_01.run()
$
one_time_munit_sample_01.one_time_set_up()
one_time_munit_sample_01.set_up()
test_sample_1()
one_time_munit_sample_01.tear_down()
one_time_munit_sample_01.set_up()
test_sample_3()
one_time_munit_sample_01.tear_down()
a sw:mtest_result
MagikSF> one_time_munit_sample_01.run()
$
one_time_munit_sample_01.set_up()
test_sample_1()
one_time_munit_sample_01.tear_down()
one_time_munit_sample_01.set_up()
test_sample_3()
one_time_munit_sample_01.tear_down()
a sw:mtest_result
MagikSF> one_time_munit_sample_02.run()
$
one_time_munit_sample_01.one_time_tear_down()
one_time_munit_sample_02.one_time_set_up()
one_time_munit_sample_02.set_up()
test_sample_2()
one_time_munit_sample_02.tear_down()
one_time_munit_sample_02.set_up()
test_sample_4()
one_time_munit_sample_02.tear_down()
a sw:mtest_result
MagikSF> one_time_munit_sample_01.run()
$
one_time_munit_sample_02.one_time_tear_down()
one_time_munit_sample_01.one_time_set_up()
one_time_munit_sample_01.set_up()
test_sample_1()
one_time_munit_sample_01.tear_down()
one_time_munit_sample_01.set_up()
test_sample_3()
one_time_munit_sample_01.tear_down()
a sw:mtest_result
I did the following. For the test exemplar I have a shared constant called "fcsi_cache" and the reset_test() empties it if true is passed. My set_up() method on the test will populate the cache once. This keeps the data in memory until you do a reset from the GUI. Probably not the most elegant solution, but gets the job done.
_pragma(classify_level=restricted)
_method test_runner_dialog.reset()
##
## Callback from reset action
##
## FCSI Mods : added true argument to call to reset_test_cases()
#---------------- HISTORY ---------------------
# (2022/08/18 - Mark Field (FCSI)) : Modified -
#----------------------------------------------
_self.reset_test_cases(_true)
_endmethod
$
_pragma(classify_level=restricted)
_private _method test_runner_dialog.reset_test_cases(_optional gui_reset?)
##
## Reset test_result on all selected test cases
##
## FCSI Mods : added gui_reset? argument to pass to test
## reset_result()
#---------------- HISTORY ---------------------
# (2022/08/18 - Mark Field (FCSI)) : Modified -
#----------------------------------------------
_for a_test _over _self.selected_tests().fast_elements()
_loop
a_test.reset_result(gui_reset?)
_self.changed(:hierarchy_tree, :redraw_keys, { a_test } )
_endloop
_endmethod
$