Extension:MWUnit

Category:Extensions incompatible with 1.42 Category:Unmaintained extensions#MWUnit Category:MIT licensed extensions
MediaWiki extensions manual
MWUnit
Release status: unmaintainedCategory:Unmaintained extensions
Implementation Special page Category:Special page extensions, Parser function Category:Parser function extensions, API Category:API extensions, ContentHandler Category:ContentHandler extensions
Description A unit testing framework for MediaWiki
Author(s) Marijn van Wezel (Xxmarijnwtalk)
Latest version 2.0.1 (2021-12-04)
Compatibility policy Master maintains backward compatibility.Category:Extensions with master compatibility policy
MediaWiki 1.31+Category:Extensions with manual MediaWiki version
PHP 7.0+
Database changes Yes
Tables mwunit_tests
mwunit_setup
mwunit_teardown
mwunit_content
mwunit_attributes
License MIT License
Download Category:Extensions in GitHub version control
  • NS_TEST (NS_TEST_TALK)
Category:All extensionsCategory:Extensions not in ExtensionJson

The MWUnit extension provides a unit testing framework for templates, parser functions and other wikitext.

It allows people that write technical templates to programmatically test those templates and changes to those templates. It ensures that a template, or section of a template, meets its design requirements and behaves exactly as intended.

MWUnit is an instance of the xUnit unit testing framework architecture.

The extension defines a number of assertions. These assertions are in the form of parser functions and test whether the given value conforms to the assertion. The most import assertions are:

  • #assert_equals - tests whether the given strings are equal
  • #assert_empty - tests whether the given string is empty
  • #assert_that - tests whether the given string is true (a string is considered true, if and only if it is "true", "yes", "on" or "1")

The complete list of available assertions can be found here.

Click through the pages in the navigation bar at the top of this page to learn about MWUnit.

Example

Below is a basic example of a full test suite (Test:Foobar). This example uses the Variables extension to show how fixtures and global state work.

<!-- Define a fixture -->
<setup>
    <!-- Define some variables -->
    {{#vardefine: bar | boofar }}
    {{#vardefine: baz | {{Example}} }}
</setup>

<!-- Define a test case -->
<testcase name="testFoobar" group="Foobar tests" context="canonical">
    <!-- Assert that the variable "bar" is equal to the string "boofar" -->
    {{#assert_equals: {{#var: bar }} | boofar }}

    <!-- Assert the variable "baz" is numeric -->
    {{#assert_is_numeric: {{#var: baz }} }}
</testcase>

<testcase name="testRisky" group="Foobar tests" context="user">
    <!-- This test would be marked as "Risky", because it contains no assertions -->
</testcase>

See also

Category:API extensions Category:All extensions Category:ArticleDeleteComplete extensions Category:BeforePageDisplay extensions Category:ContentHandlerDefaultModelFor extensions Category:ContentHandler extensions Category:Extensions in GitHub version control Category:Extensions incompatible with 1.42 Category:Extensions not in ExtensionJson Category:Extensions which add rights Category:Extensions with manual MediaWiki version Category:Extensions with master compatibility policy Category:LoadExtensionSchemaUpdates extensions Category:MIT licensed extensions Category:MovePageIsValidMove extensions Category:PageContentSaveComplete extensions Category:ParserFetchTemplate extensions Category:ParserFirstCallInit extensions Category:Parser function extensions Category:SkinBuildSidebar extensions Category:Special page extensions Category:UnitTestsList extensions Category:Unmaintained extensions