Extension:MWUnit/Writing tests

This section shows how to write tests using MWUnit. The example below shows how to write a test that exercise a specific template. The example introduces basic concepts and conventions for writing tests with MWUnit.


 * 1) The test for a template   go on the page  ;
 * 2) The tests are between   and   tags;
 * 3) The name of a test typically starts with "test", and is written in camel case;
 * 4) Inside the tests are a number of assertions, such as  ;
 * 5) Any set up should be done at the top of the page, and never in between tests.







Testing in user context
By default, tests are ran in a canonical context. This means the parser is initialized with an anonymous user and the content language. This is done to make the output of the test consistent across users and languages.

You can choose to run a specific test in user context. A test run in user context will initialize the parser with the current logged in user and the language that user has set. This can be useful for testing templates that depend on which user is logged in or which language is selected.

The context of a test can be set by using the  annotation, as shown in this example:

 ...

 ...