Modulus:UnitTests/doc
This is the documentation page for Modulus:UnitTests
Subpagina haec est documentatio de Modulus:UnitTests. Hic legitur quomodo uti, ac categoriae, nexus invervici et cetera continentur qui modulus in origine non continet. |
Purpose
+/-This module facilitates creating unit tests for Lua modules.
Put the following at Module:name/testcases
:
local tests = require('Module:UnitTests')
function tests:test_example()
--[[ here be the tests ]]
end
return tests
Then put the following on Module:name/testcases/documentation
:
{{#invoke:name/testcases|run_tests}}
Tests should be written as Lua methods whose names start with test
. The self
object contains the following methods, which may be called from the method:
- preprocess_equals(text, expected, options)
- Will check whether expanding templates in
text
results inexpected
. - preprocess_equals_many(prefix, suffix, cases, options)
- preprocess_equals_preprocess(text1, text2, options)
- Will check whether expanding templates in
text1
andtext2
results in the same string. - preprocess_equals_preprocess_many(prefix1, suffix1, prefix2, suffix2, cases, options)
- equals(name, actual, expected, options)
- Will check whether two primitive values are equal.
name
will be used as the row header. When the value is a table,equals_deep
should be used. - equals_deep(name, actual, expected, options)
- Will check whether two values, which may be tables, are equal.
name
will be used as the row header.
options
should be given in a table or omitted. Currently, the only option supported is nowiki
, which will cause both the expected and the actual values to be wrapped in <nowiki> tags when rendering the results table.