memory alpha

UnitTests provides a unit test facility that can be used by other scripts using require. See Wikipedia:Lua#Unit testing for details. The following is a sample from Module:UnitTests/testcases/Module:Example:

local p = require('Module:UnitTests')

function p:test_hello()
	self:preprocess_equals('{{#invoke:Example|hello}}', 'Hello World!')
end

return p

The documentation subpage Module:UnitTests/testcases/Module:Example/doc executes it with {{#invoke:UnitTests/testcases/Module:Example|run_tests}}. Test methods like test_hello above must begin with "test".

Methods

run_tests

preprocess_equals

preprocess_equals_many

preprocess_equals_preprocess

preprocess_equals_preprocess_many

preprocess_equals_sandbox_many

equals

equals_deep

Test options

These are the valid options that can be passed into the options parameters of the test functions listed above.

nowiki

Enabling this wraps the output text in <nowiki>...</nowiki> tags to avoid the text being rendered (e.g. <span>[[Example|Page]]</span> instead of Page)

combined

Enabling this will display the output text in both the rendered mode and the nowiki mode to allow for both a raw text and visual comparison.

noexpectation

Enabling this and providing an empty string as an expected value makes a test always succeed, regardless of the actual value.

templatestyles

Enabling this fixes the IDs in the strip markers <templatestyles>...</templatestyles> produces when processed to avoid incorrectly failing the tests.

stripmarker

Enabling this fixes the IDs in all strip markers produces when processed to avoid incorrectly failing the tests.

display

An optional function that changes how the output from the tests are displayed. This doesn't affect the comparison process.