Simple Unit Tests by Dannii Willis Search for other extensions by this author

Versions

Download version 1/130803For Inform 7 6G60

Links

Description

Very simple unit tests.

Tags testing

Documentation

This extension adds support for simple unit tests. Group tests together in rules added to the Unit test rulebook, and make individual tests with the assert phrase: Unit test: assert that 5 is 5; assert that "happy" is "happy"; Simple Unit Tests uses Text Capture by Eric Eve to capture any text that is said between assertions. You can use "the captured output" to have the captured text automatically stripped of whitespace at its beginning and end. If you need to capture a lot of text then you will need to increase the buffer size used by Text Capture; see that extension for details. Unit test: say "happy"; assert that the captured output is "happy"; Failed assertions will display an error message. If you are asserting that two values are the same then the expected and actual values will be displayed. If you give your test rules names, those names will be displayed. So running Unit test (this is the failing rule): assert that 2 plus 2 is 5; assert that the player encloses a room; produces Failure for test: failing, assertion: 1. Expected: 5, Got: 4 Failure for test: failing, assertion: 2. (Asserted condition is false) 2 of 2 assertions failed. If you are writing an extension, we suggest you name all your test rules, and that you place your tests under a section titled: (not for release) (for use with Simple Unit Tests by Dannii Willis) The state of the VM will be saved before and restored after the unit tests are run, so you don't need to worry about your tests changing anything permanently. Lastly, run the tests by entering the command "run the unit tests" (or just simply "unit"), or use "try running the unit tests" in your code. Happy testing! The latest version of this extension can be found at <https://github.com/i7/extensions>. This extension is released under the Creative Commons Attribution licence. Bug reports, feature requests or questions should be made at <https://github.com/i7/extensions/issues>. Example: * Basic Unit Tests - Passing and Failing *: "Basic Unit Tests" Include Simple Unit Tests by Dannii Willis. Test room is a room. Unit test (this is the passing rule): assert 5 is 5; assert 2 plus 2 is 4; assert {1, 2, 3} is {1, 2, 3}; assert "happy" is "happy"; say "hello!"; assert the captured output is "hello!"; assert the score is 0; assert the player is enclosed by the location; Unit test (this is the failing rule): assert {1, 2, 3} is {1, 2, 3, 4}; assert "happy" is "sad"; say "hello!"; assert the captured output is "goodbye!"; assert the player encloses a room; When play begins: try running the unit tests;