Extension:MWUnit/Organizing tests

From mediawiki.org

MWUnit supports several ways to group and organize tests. This page explains how to appropriately organize tests.

An important property of MWUnit is that tests are composable. You are able to run any number of tangential tests together. For instance, all tests in a group, or all tests on a test page, all tests covering a template, or an individual test.

Composing a group[edit]

Any test must belong to a group. A test must be added to a specific group using the group annotation, as shown in this example:

<testcase name="testGroup" group="foobar">

Not having this annotation will result in an error.

Tests in the same group can be run together, but are not necessarily in the same fixture. This means that tests in the same group may not necessarily share the same global and parser state. Only tests that are on the same page will share the same fixture.

Tests in the same group can be run together via the special page.

It is good practice to group tests together that test a certain feature of your wiki. If you have a set of templates that are only used to render the Main Page, it is good practice to put all tests covering these templates in one group.

Organizing tests on a test page[edit]

A test page is any page in the Test namespace. It can contain one or many tests. Each test on a test page shares the same parser and global state. A single test page should preferably test one, and only one, template (or some other "unit" of wikitext, such as a parser function).

Tests on the same test page can be run in a group only via the test page itself. It can be done by pressing the "Run unit tests" button in the side menu.

See also[edit]