Module:UnitTests/doc explained
UnitTests provides a unit test facility that can be used by other scripts using require. See for details. The following is a sample from :
The talk page executes it with <nowiki>{{#invoke: Example/testcases | run_tests}}</nowiki>
. Test methods like test_hello above must begin with "test".
Methods
run_tests
- : Runs all tests. Normally used on talk page of unit tests.
- If is specified, a column will be added showing the first character position where the expected and actual results differ.
- If is specified, failed tests will be highlighted to make them easier to spot. A user script that moves failed tests to the top is also available.
- If is specified, the header will show the columns "Test", "Live", "Sandbox", "Expected". This is required when using the method.
preprocess_equals
- : Gives a piece of wikitext to preprocess and an expected resulting value. Scripts and templates can be invoked in the same manner they would be in a page.
self:preprocess_equals('', 'Hello, world!',)
preprocess_equals_many
- : Performs a series of preprocess_equals calls on a set of given pairs. Automatically adds the given prefix and suffix to each text.
self:preprocess_equals_many('',,)
preprocess_equals_preprocess
- : Gives two pieces of wikitext to preprocess and determines if they produce the same value. Useful for comparing scripts to existing templates.
self:preprocess_equals_preprocess('', '',)
preprocess_equals_preprocess_many
- : Performs a series of preprocess_equals_preprocess calls on a set of given pairs. The prefix/suffix supplied for both arguments is added automatically. If in any case the second part is not specified, the first part will be used.
self:preprocess_equals_preprocess_many('', '',,)
preprocess_equals_sandbox_many
- : Performs a series of preprocess_equals_compare calls on a set of given pairs. The test compares the live version of the module vs the /sandbox version and vs an expected result. Ensure live_sandbox is specified or there may be some errors in the output.
self:preprocess_equals_sandbox_many('