User:Rodasmith/wUnit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Purpose[edit]

Wiki templates can become complex. When one template relies on other templates, changes to one can affect the other in subtle ways.

To manage such complexity, most other software development environments incorporate automated unit testing into each project. Many modern successful unit test suites are built on jUnit and nUnit, but wiki templates have no such framework. Enter wUnit, a unit testing framework for wiki templates.

Usage[edit]

To execute a wUnit test suite, execute it by invoking the test suite, typically located in a "test" subdirectory of the template to test. The test suite for a template {{foo}}, for example, would be at Template:foo/test. Including the test suite will execute it and show the total number of tests, the number of tests that passed, and the number of tests that fail.

E.g., the test suite at Template:foo/test currently shows the following results:

Template:foo/test

Components[edit]

A package of assertion methods is at User:Rodasmith/wUnit/Assert.

E.g.:

==Unit tests for {{temp|foo}}==
{{User:Rodasmith/wUnit/TestSuite |
{{User:Rodasmith/wUnit/Assert.AreEqual| {{foo|bar|1}} | <span class="bar">1</span> }} |
{{User:Rodasmith/wUnit/Assert.IsEmpty| {{foo|||}} }}
}}

The results of the above test follow:

Unit tests for {{foo}}

  • Total number of tests: 2
  • Tests passed: 0
  • Tests failed: 2

Details[edit]

Assertion failed. Expected: {{{expected}}}. Actual: {{{actual}}}

User:Rodasmith/wUnit/Assert.IsEmpty