User:Xxmarijnw/Extension:MWUnit/Writing tests

This page documents how to write tests for MWUnit. The example below shows how to write a test that exercises a specific template. The example introduces basic concepts and conventions for writing tests with MWUnit:


 * 1) The test for a template   goes 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 or snake case;
 * 4) Inside the tests are a number of assertions, such as  ;







Testing in user context
By default, tests are run 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 more 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 or the user specified in the  annotation 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:



