brl_maxunit.md 2.5 KB


id: brl.maxunit title: BRL.MaxUnit

sidebar_label: Introduction

A unit testing Module based loosely on JUnit.

To define a test :
  1. implement a sub-Type of TTest
  2. initialize the user states by creating a Method tagged with {before}
  3. clean-up after a test by creating a Method tagged with {after}.
Here is an example:

Type MyTest Extends TTest

	Local value1:Int
	Local value2:Int

	Method setup() { before }
		value1 = 2
		value2 = 3
	End Method

End Type

For each test implement a Method which interacts with the fixture. You tell MaxUnit that this is a test Method by tagging it with {test}. The Method can otherwise be called anything you like. It should take no parameters and not return anything.
Verify the expected results with assertions specified by calling assertTrue with a boolean.

	Method testAdd() { test }
		Local result:Int = value1 + value2
		assertTrue(result = 5)
	End Method

Finally, you can run the tests by creating an instance of the TTestSuite and calling its run method.

New TTestSuite.run()

The following code snippet is a complete example, including a failed test :
You can open the source here.

SuperStrict

Import BRL.MaxUnit

New TTestSuite.run()

Type MyTest Extends TTest

	Field  value1:Int
	Field value2:Int

	Method setup() { before }
		value1 = 2
		value2 = 3
	End Method

	Method testAdd() { test }
		Local result:Int = value1 + value2
		assertTrue(result = 5)
	End Method
	
	Method testMultiply() { test }
		Local result:Int = value1 * value2
		assertEqualsI(6, result)
	End Method

	Method testOops() { test }
		Local result:Int = value1 + value2
		assertEqualsI(2, result, "Just here to show a failed test...")
	End Method

End Type

The above program should produce the following output :

[0] ..F

There was 1 failure:
1) testOops
    assertEqualsI() : Just here to show a failed test... expected:<2> but was:<5>


FAILURES!!!
Tests run: 3,  Failures: 1,  Errors: 0
Time: 0.0

Process complete

Types

Type Description
TTest A test defines a set of test methods to test.
TTestSuite A test suite defines the fixture to run multiple tests.
AssertionFailedException Failed assertion.
TAssert A set of assert methods.