Module:UnitTests/doc: Difference between revisions

Content deleted Content added
No edit summary
Prune code duplication
Line 1:
UnitTests provides a unit test facility that can be used by other scripts using '''require'''. See [[Wikipedia:Lua#Unit_testing]] for details. Following is a sample from [[Module:Bananas/testcases]]:
 
<{{#tag:syntaxhighlight |{{Module:Bananas/testcases}}|lang="lua">}}
-- Unit tests for [[Module:Bananas]]. Click talk page to run tests.
local p = require('Module:UnitTests')
 
function p:test_hello()
self:preprocess_equals('{{#invoke:Bananas | hello}}', 'Hello, world!',{nowiki=1})
end
 
return p
</syntaxhighlight>
 
The talk page [[Module talk:Bananas/testcases]] executes it with <code><nowiki>{{#invoke: Bananas/testcases | run_tests}}</nowiki></code>. Test methods like test_hello above must begin with "test".