Test Case

Test Case is a central element of the testing framework. In order to create a test case you need to create a slotted exemplar which inherits from test_case parent exemplar. The test_case exemplar comes from MUnit base module, which is loaded to the session when any test is being run. To create new test case use New Test Case wizard.

Test Cases with Fixtures

Test fixture is a fixed state of a set of slots, used as a baseline for running tests. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run, so that the results are repeatable. Test cases differ from the slotted exemplars due to test and fixture lifecycle methods:

To define a test case with fixtures:

  1. Implement a subclass of test_case.
  2. Define slots that store the state of the fixture.
  3. Initialize the fixture state by overriding set_up().
  4. Clean-up after a test by overriding tear_down().
  5. Implement test methods which interacts with the fixture.

Each test runs in its own fixture, so there can be no side effects between test runs. You can verify the expected results with the specified assertions by calling any of available assert() methods.

Here is an example:

_pragma(classify_level=basic, usage={subclassable})
def_slotted_exemplar(:simple_test_case, {
   { :value1 , _unset },
   { :value2 , _unset }
}, {:test_case})


_pragma(classify_level=basic, usage={subclassable})
_method simple_test_case.set_up()
  .value1 << 2.0
  .value2 << 3.0

_pragma(classify_level=basic, usage={subclassable})
_method simple_test_case.test_add()
   result << .value1 + .value2
   _self.assert_equals( 5.0 ,result)

Note: To run a method as a test, the method name must start with test_ and end with brackets. Test methods should have some input parameters.

Related concepts

MUnit Base Module

Related reference

New Test Case wizard
MUnit test launcher