<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://secrets.warcraftwatch.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AUnitTests%2Fdoc</id>
	<title>Module:UnitTests/doc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://secrets.warcraftwatch.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AUnitTests%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://secrets.warcraftwatch.com/w/index.php?title=Module:UnitTests/doc&amp;action=history"/>
	<updated>2026-05-06T16:11:14Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://secrets.warcraftwatch.com/w/index.php?title=Module:UnitTests/doc&amp;diff=7234&amp;oldid=prev</id>
		<title>imported&gt;Surafbrov at 15:29, 24 November 2019</title>
		<link rel="alternate" type="text/html" href="https://secrets.warcraftwatch.com/w/index.php?title=Module:UnitTests/doc&amp;diff=7234&amp;oldid=prev"/>
		<updated>2019-11-24T15:29:25Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;UnitTests provides a unit test facility that can be used by other scripts using &amp;#039;&amp;#039;&amp;#039;require&amp;#039;&amp;#039;&amp;#039;. See [[wikipedia:Wikipedia:Lua#Unit testing]] for details. Following is a sample from [[Module:Bananas/testcases]]:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;-- Unit tests for [[Module:Bananas]]. Click talk page to run tests.&lt;br /&gt;
local p = require(&amp;#039;Module:UnitTests&amp;#039;)&lt;br /&gt;
 &lt;br /&gt;
function p:test_hello()&lt;br /&gt;
    self:preprocess_equals(&amp;#039;{{#invoke:Bananas | hello}}&amp;#039;, &amp;#039;Hello, world!&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
return p&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The talk page [[Module talk:Bananas/testcases]] executes it with &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#invoke: Bananas/testcases | run_tests}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;. Test methods like test_hello above must begin with &amp;quot;test&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Methods ==&lt;br /&gt;
=== run_tests ===&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;run_tests(differs_at)&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;: Runs all tests. If &amp;quot;differs_at=1&amp;quot; is specified, a column will be added showing the first character position where the expected and actual results differ. Normally used on talk page of unit tests.&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#invoke:Bananas/testcases|run_tests}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals ===&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;preprocess_equals(text, expected)&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;: 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.&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;self:preprocess_equals(&amp;#039;{{#invoke:Bananas | hello}}&amp;#039;, &amp;#039;Hello, world!&amp;#039;)&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals_many ===&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;preprocess_equals_many(prefix, suffix, cases)&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;: Performs a series of preprocess_equals() calls on a set of given pairs. Automatically adds the given prefix and suffix to each text.&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;self:preprocess_equals_many(&amp;#039;{{#invoke:BananasArgs | add |&amp;#039;, &amp;#039;}}&amp;#039;, {&lt;br /&gt;
        {&amp;#039;2|3&amp;#039;, &amp;#039;5&amp;#039;},&lt;br /&gt;
        {&amp;#039;-2|2&amp;#039;, &amp;#039;0&amp;#039;},&lt;br /&gt;
    })&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals_preprocess ===&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;preprocess_equals_preprocess(text, expected)&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;: Gives two pieces of wikitext to preprocess and determines if they produce the same value. Useful for comparing scripts to existing templates.&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;self:preprocess_equals_preprocess(&amp;#039;{{#invoke:Bananas | hello}}&amp;#039;, &amp;#039;{{Hello}}&amp;#039;)&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals_preprocess_many ===&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;preprocess_equals_preprocess_many(prefix, suffix, cases)&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;: 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.&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;    self:preprocess_equals_preprocess_many(&amp;#039;{{#invoke:Foo | spellnum |&amp;#039;, &amp;#039;}}&amp;#039;, &amp;#039;{{spellnum&amp;#039;, &amp;#039;}}&amp;#039;, {&lt;br /&gt;
        {&amp;#039;2&amp;#039;}, -- equivalent to {&amp;#039;2&amp;#039;,&amp;#039;2&amp;#039;},&lt;br /&gt;
        {&amp;#039;-2&amp;#039;, &amp;#039;-2.0&amp;#039;},&lt;br /&gt;
    })&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== equals ===&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;equals(name, actual, expected)&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;: Gives a computed value and the expected value, and checks if they are equal according to the == operator. Useful for testing modules that are designed to be used by other modules rather than using #invoke.&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;self:equals(&amp;#039;Simple addition&amp;#039;, 2 + 2, 4)&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== equals_deep ===&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;equals_deep(name, actual, expected)&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;: Like equals, but handles tables by doing a deep comparison. Neither value should contain circular references, as they are not handled by the current implementation and may result in an infinite loop.&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;self:equals_deep(&amp;#039;Table comparison&amp;#039;, createRange(1,3), {1,2,3})&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Module:ScribuntoUnit]] – alternative unit test module&lt;br /&gt;
&lt;br /&gt;
&amp;lt;includeonly&amp;gt;[[Category:Modules]]&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;[[Category:Modules documentation]]&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>imported&gt;Surafbrov</name></author>
	</entry>
</feed>