User:Xxmarijnw/Extension:MWUnit/Getting started

This tutorial assumes you have MWUnit installed and working correctly. In this tutorial, you will learn how to write a simple unit test as well as how to run tests.

The documentation on how to install MWUnit can be found here.

Creating a test
To get started, we will create a new template which we will call. This template adds  to the first argument. It returns an error if and only if the first argument is not a number.

We will also create the associated test page for this template. We'll call test page.

Here is what the two pages might look like:

Template:AddTen
This is the "AddTen" template.

-> 22 -> 10    -> 10

Test:AddTen








That is all it takes to create a new test. This fixture contains four tests with the same fixture. In this case, each test tests exactly one aspect of the template, but this is not required. It is recommended however. Every test we wrote is in the group. Any test we write must be in a group. Grouping similar tests together makes 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 global state.

Running tests
There are several ways to run a test. The most obvious way, is to click on the "Run unit tests" button in the side bar of a test page. Clicking this button will run all tests on the current test page.

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.