Assertions

MUnit assertions are in other words methods used to determine the state of a test. These methods usually start with assert prefix and must be executed directly within the test method. Every test case automatically inherits these methods from assert exemplar, so they can be called using _self.

Predefined assertions

Method Description
fail(_optional a_message) Fails a test method with the given a_message.
assert_equals( expected , actual , _optional a_message) Assert that expected and actual are equal. If assertion fails then condition assertion_failed_warning is raised with the given a_message.
assert_is( expected , actual, _optional a_string) Assert that expected and actual are identical. If assertion fails then condition assertion_failed_warning is raised with the given a_message.
assert_is_not( expected , actual, _optional a_string) Assert that expected and actual are not identical. If assertion fails then condition assertion_failed_warning is raised with the given a_message.
assert_not_equals( expected , actual, _optional a_string) Assert that expected and actual are not equal. If assertion fails then condition assertion_failed_warning is raised with the given a_message.
assert_false( actual, _optional a_string ) Assert that actual is _false. If assertion fails then condition assertion_failed_warning is raised with the given a_message.
assert_true( actual, _optional a_string ) Assert that actual is _true. If assertion fails then condition assertion_failed_warning is raised with the given a_message.
assert_unset( actual, _optional a_string ) Assert that actual is _unset If assertion fails then condition assertion_failed_warning is raised with the given a_message.
assert_not_unset( actual, _optional a_string ) Assert that actual is not _unset If assertion fails then condition assertion_failed_warning is raised with the given a_message.

Advanced assertions

Method Description
assert_equals( expected , actual , _optional a_message ,_optional delta ,_optional relative?)

Assert that expected and actual are equal.

For numbers assert that expected and actual are equal concerning a delta. Delta can be absolute value or if relative? is true then delta is relative value

Relative delta = 0.2 means that actual value have to be in the range form expected value - 20% to expected value + 20 %.)

Absolute value of delta from relative value is calculated by:

ABS_DELTA = REL_DELTA * EXPECTED
assert( left_operand , an_operator ,_optional right_operand , a_message) Function used to build custom expressions based on values (left_operand and right_operand) and an_operator. If assertion fails then condition assertion_failed_warning is raised with the given a_message. An_operator may be one of predefined symbols:

Basic operators

  • :is - left_operand is the same as right_operand
  • :isnt - left_operand is not the same as right_operand

Binary operators

  • :|=|
  • :|~=|
  • :|<|
  • :|>|
  • :|<=|
  • :|>=|

Method operators

All methods that return _true or _false e.g. :
:|is_kind_of?()| ,
:|is_class_of?()| ,
:|inherits_from?()|,
:|responds_to?()|,
:|includes?()|

Examples

_self.assert( exp , :is , :test )
_self.assert( exp , :|=| , "test" )
_self.assert( exp , :|<| , 25 )
_self.assert( {3,4,5} , :|includes?()| , exp )
_self.assert( act , :|your_test_that_returns_boolean?()| , exp )

Related concepts

Test Case

Related reference

New Test Case wizard
MUnit test launcher