Board Thread:Lua Help/@comment-24473195-20150912113753

There are primarily two modules that help run tests:


 * https://en.wikipedia.org/wiki/Module:UnitTests
 * https://en.wikipedia.org/wiki/Module:ScribuntoUnit

The general idea is to create a new module that will import one of those two modules and create tests that evaluate the actual output against the expected output.

Example:

-- Unit tests for Module:Bananas. Click talk page to run tests. local p = require('Module:UnitTests') function p:test_hello self:preprocess_equals('', 'Hello, world!',{nowiki=1}) end return p

Output:

I also created Module:Testharness which facilitates the use of this. Rather than entering all that information for every single module, all you need to do is enter something like:

-- Unit tests. Click talk page to run tests. local p ={ main={--function being tested options={nowiki=false}, --options -apply nowiki to test results tests = { preprocess_equals_many ={ -- Parameters     - Expected result {'Hello World!'  , 'Hello World!'}, {'1=Hello|2=World', 'Hello'}, },       },    }, } return p Hope this helps... 