123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <img src="logo.png" align="right" />
- <p>A unit testing Module based loosely on JUnit.</p>
- To define a test :<br/>
- <ol>
- <li> implement a sub-Type of TTest</li>
- <li> initialize the user states by creating a Method tagged with `{before}`</li>
- <li> clean-up after a test by creating a Method tagged with `{after}`.</li>
- </ol>
- Here is an example:
- ```blitzmax
- 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.<br/>
- Verify the expected results with assertions specified by calling @assertTrue with a boolean.
- ```blitzmax
- 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.
- ```blitzmax
- New TTestSuite.run()
- ```
- The following code snippet is a complete example, including a failed test :<br/>
- You can open the source <a href="example.bmx">here</a>.
- ```blitzmax
- 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
- ```
|