MediaWiki extensions manual
Release status: experimental
Implementation Special page , Parser function , Tag
Description A unit testing framework for MediaWiki
Author(s) Marijn van Wezel (Xxmarijnwtalk)
Latest version 0.5.1 (06-07-21)
Compatibility policy Master maintains backward compatibility.
MediaWiki 1.31+
PHP 7.0+
Database changes Yes
Tables tests
License MIT License
Translate the Xxmarijnw/Extension:MWUnit extension if it is available at

MWUnit is an extension for MediaWiki that provides a unit testing framework for templates, parser functions and other wikitext.

It allows people who write technical templates to automatically 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.


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 works.

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

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

    {{#if: {{Boofar}} | 
        <!-- Only run these assertions if the template "Boofar" is not empty -->
        {{#assert_is_equal: {{Boofar}} | {{#var: bar }} }}

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

See alsoEdit