User:Xxmarijnw/Extension:MWUnit/Getting started

This tutorial assumes you have MWUnit installed and working. In this tutorial, you will learn how to write and run a simple unit test for the fictional template. The documentation on how to install MWUnit can be found on this page.

Creating a test
We will create a new template,. This template adds  to the first argument, or   to   if no argument is given. It returns an error if and only if the first argument is not a number. This template makes use of the ParserFunctions extension.

We will also create the associated test page for this template, which we will appropriately call. Here is what these two pages may look like:

Template:AddTen
This is the "AddTen" template.

-> 22 -> 10    -> 10  -> Expression error: Unrecognized word "foo".

Test:AddTen








The test page we have created contains four test cases. Each test case should test exactly one distinct thing of the template that is being tested. In this case, the first test case tests if adding  to   results in , the second test tests whether the first parameter can be left empty, and so on.

As you can see, each test has the same "group" attribute. Grouping similar tests together make it easier to execute them in bulk, since we can run every test in a certain group. Tests in the same group are not required to be on the same page.

Running tests
There are several ways to run a test. The most obvious way is to click the "Run tests" button in the sidebar on a test page. Clicking this button will run all tests on the current test page. If you are using a skin that hides this button, the shortcut  can also be used.

Another way to run a test is to go to the special page.