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.

These test cases all share the same global state, defined at the top of the test page. This is what we call a fixture. This test does not need a global state, so nothing is defined at the top of the page.

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 easily run every test in a certain group. Tests in the same group are not required to be in the same fixture. This means we can have two tests in the same group, but on two different test pages. When we execute the group of tests, both pages are executed separately and do not share a global state.

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

Another way to run a test is to go to the special page. This special page contains two forms, one for running tests in a group, and one for running an individual test. You must choose the group or test you want to execute, and click. Depending on the number of tests and the complexity of the test, it might take some time for the results to be shown. Please be patient.