<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://70.231.62.181/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="http://70.231.62.181/index.php?action=history&amp;feed=atom&amp;title=Module%3AUnitTests%2Fdoc"/>
	<link rel="alternate" type="text/html" href="http://70.231.62.181/index.php?title=Module:UnitTests/doc&amp;action=history"/>
	<updated>2026-04-23T01:39:12Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>http://70.231.62.181/index.php?title=Module:UnitTests/doc&amp;diff=13062977&amp;oldid=prev</id>
		<title>imported&gt;Zackmann08: +high use</title>
		<link rel="alternate" type="text/html" href="http://70.231.62.181/index.php?title=Module:UnitTests/doc&amp;diff=13062977&amp;oldid=prev"/>
		<updated>2025-12-06T22:59:36Z</updated>

		<summary type="html">&lt;p&gt;+high use&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{high-use}}&lt;br /&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:Lua#Unit_testing]] for details. The following is a sample from [[Module:Example/testcases]]:&lt;br /&gt;
&lt;br /&gt;
{{#tag:syntaxhighlight|&lt;br /&gt;
-- Unit tests for [[Module:Example]]. 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;&amp;lt;nowiki&amp;gt;{{#invoke:Example | hello}}&amp;lt;/nowiki&amp;gt;&amp;#039;, &amp;#039;Hello World!&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;br /&gt;
|lang=&amp;quot;lua&amp;quot;}}&lt;br /&gt;
&lt;br /&gt;
The talk page [[Module talk:Example/testcases]] executes it with &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#invoke: Example/testcases | run_tests}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;. Test methods like test_hello above &amp;#039;&amp;#039;&amp;#039;must begin with&amp;#039;&amp;#039;&amp;#039; &amp;quot;&amp;#039;&amp;#039;&amp;#039;test&amp;#039;&amp;#039;&amp;#039;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Methods ==&lt;br /&gt;
=== run_tests ===&lt;br /&gt;
* {{code|1=run_tests}}: Runs all tests. Normally used on talk page of unit tests. &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot;&amp;gt;&lt;br /&gt;
{{#invoke:Example/testcases|run_tests}}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* If {{code|1=differs_at}} is specified, a column will be added showing the first character position where the expected and actual results differ. &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot;&amp;gt;&lt;br /&gt;
{{#invoke:Example/testcases|run_tests|differs_at=1}}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* If {{code|1=highlight}} is specified, failed tests will be highlighted to make them easier to spot. A [[WP:USERSCRIPT|user script]] that [[User:Fred_Gandt/moveFailedModuleTestsToTop.js|moves failed tests to the top]] is also available. &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot;&amp;gt;&lt;br /&gt;
{{#invoke:Example/testcases|run_tests|highlight=1}}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* If {{code|1=live_sandbox}} is specified, the header will show the columns &amp;quot;Test&amp;quot;, &amp;quot;Live&amp;quot;, &amp;quot;Sandbox&amp;quot;, &amp;quot;Expected&amp;quot;. This is required when using the {{code|1=preprocess_equals_sandbox_many}} method.&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals ===&lt;br /&gt;
* {{code|1=preprocess_equals(text, expected, options)}}: 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. &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
self:preprocess_equals(&amp;#039;{{#invoke:Example | hello}}&amp;#039;, &amp;#039;Hello, world!&amp;#039;, {nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals_many ===&lt;br /&gt;
* {{code|1=preprocess_equals_many(prefix, suffix, cases, options)}}: Performs a series of preprocess_equals() calls on a set of given pairs. Automatically adds the given prefix and suffix to each text. &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
self:preprocess_equals_many(&amp;#039;{{#invoke:Example | hello_to |&amp;#039;, &amp;#039;}}&amp;#039;, {&lt;br /&gt;
    {&amp;#039;John&amp;#039;, &amp;#039;Hello, John!&amp;#039;},&lt;br /&gt;
    {&amp;#039;Jane&amp;#039;, &amp;#039;Hello, Jane!&amp;#039;},&lt;br /&gt;
}, {nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals_preprocess ===&lt;br /&gt;
* {{code|1=preprocess_equals_preprocess(text, expected, options)}}: Gives two pieces of wikitext to preprocess and determines if they produce the same value. Useful for comparing scripts to existing templates. &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
self:preprocess_equals_preprocess(&amp;#039;{{#invoke:Example | hello}}&amp;#039;, &amp;#039;{{Hello}}&amp;#039;, {nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals_preprocess_many ===&lt;br /&gt;
* {{code|1=preprocess_equals_preprocess_many(prefix1, suffix1, prefix2, suffix2, cases, options)}}: 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. &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
self:preprocess_equals_preprocess_many(&amp;#039;{{#invoke:ConvertNumeric | numeral_to_english|&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;
}, {nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals_sandbox_many ===&lt;br /&gt;
* {{code|1=preprocess_equals_sandbox_many(module, function, cases, options)}}: Performs a series of preprocess_equals_compare() calls on a set of given pairs. The test compares the live version of the module vs the /sandbox version and vs an expected result. Ensure live_sandbox is specified or there may be some errors in the output. &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
self:preprocess_equals_sandbox_many(&amp;#039;{{#invoke:Example&amp;#039;, &amp;#039;hello_to&amp;#039;, {&lt;br /&gt;
    {&amp;#039;John&amp;#039;, &amp;#039;Hello, John!&amp;#039;},&lt;br /&gt;
    {&amp;#039;Jane&amp;#039;, &amp;#039;Hello, Jane!&amp;#039;},&lt;br /&gt;
}, {nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== equals ===&lt;br /&gt;
* {{code|1=equals(name, actual, expected, options)}}: 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. &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
self:equals(&amp;#039;Simple addition&amp;#039;, 2 + 2, 4, {nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== equals_deep ===&lt;br /&gt;
* {{code|1=equals_deep(name, actual, expected, options)}}: 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. &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
self:equals_deep(&amp;#039;Table comparison&amp;#039;, createRange(1,3), {1,2,3}, {nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test options ==&lt;br /&gt;
These are the valid options that can be passed into the options parameters of the test functions listed above.&lt;br /&gt;
&lt;br /&gt;
=== nowiki ===&lt;br /&gt;
Enabling this wraps the output text in {{tag|nowiki}} tags to avoid the text being rendered (E.g. &amp;lt;nowiki&amp;gt;&amp;lt;span&amp;gt;[[Example|Page]]&amp;lt;/span&amp;gt;&amp;lt;/nowiki&amp;gt; instead of &amp;lt;span&amp;gt;[[Example|Page]]&amp;lt;/span&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
=== combined ===&lt;br /&gt;
{{hatnote|Only available in &amp;lt;code&amp;gt;preprocess_equals&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;preprocess_equals_preprocess&amp;lt;/code&amp;gt;}}&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== templatestyles ===&lt;br /&gt;
{{hatnote|Only available in &amp;lt;code&amp;gt;preprocess_equals&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;preprocess_equals_preprocess&amp;lt;/code&amp;gt;}}&lt;br /&gt;
Enabling this fixes the IDs in the [[mw:Strip marker|strip markers]] {{tag|templatestyles}} produces when processed to avoid incorrectly failing the tests.&lt;br /&gt;
&lt;br /&gt;
=== stripmarker ===&lt;br /&gt;
{{hatnote|Only available in &amp;lt;code&amp;gt;preprocess_equals&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;preprocess_equals_preprocess&amp;lt;/code&amp;gt;}}&lt;br /&gt;
Enabling this fixes the IDs in &amp;#039;&amp;#039;all&amp;#039;&amp;#039; strip markers produces when processed to avoid incorrectly failing the tests.&lt;br /&gt;
&lt;br /&gt;
=== display ===&lt;br /&gt;
{{hatnote|Only available in &amp;lt;code&amp;gt;equals&amp;lt;/code&amp;gt;}}&lt;br /&gt;
An optional function that changes how the output from the tests are displayed. This doesn&amp;#039;t affect the comparison process.&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;{{#ifeq:{{SUBPAGENAME}}|sandbox||&lt;br /&gt;
&amp;lt;!-- Categories go here and interwikis go in Wikidata. --&amp;gt;&lt;br /&gt;
[[Category:Modules for test tools]]&lt;br /&gt;
[[Category:Modules that check for strip markers]]&lt;br /&gt;
}}&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>imported&gt;Zackmann08</name></author>
	</entry>
</feed>