Jump to content

Wikipedia:Template sandbox and test cases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Chochopk (talk | contribs) at 08:36, 8 June 2007 (create). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Templates are a very powerful feature of MediaWiki, but mistakes can be easily made, even by experienced users. Complex templates should therefore be accompanied by sandboxes and test casees to prevent bugs.

For what kind of templates

It is recommended to apply the test case pattern to templates that can generate very different looking output, such as the ones that take many parameters, or the ones that have many branches of the #switch operator.

For navigational boxes, of which the outputs are almost identical on each transcluding page, the benefit may not outweight the time and effort.

Prerequisite

The template must be properly documented following Wikipedia:Template documentation.

Furthermore, the template should not have too many interleaving <includeonly> and <noinclude> blocks. A hat note and the documentation in their respestive <noinclude> block would be appropriate.

How to create sandbox and test case subpages

  1. Suppose your template is named Template:X. Create a subpage with the name Template:X/sandbox and another with Template:X/testcases. When both of these subpages are present, the documentation would include links to them.
  2. Copy only the code (everything that is not surrounded by <noinclude>) from your Template:X to Template:X/sandbox. It would be nice if you put proper edit summary at this step.
  3. Copy a few transcluding examples from articles ({{X | .... }}) to your Template:X/testcases. In the test case subpage, replace all instances of X to X/testcases.

How to use them subsequently

  1. Sync sandbox from the real template (i.e. step 2 above)
  2. Have fun editing the sandbox
  3. Verify the test cases
  4. If everything looks good, import the code from the sandbox to the real template

It is recommended to use a tabbed browser and open the test case subpage before changing the sandbox, and another after changing the sandbox. This can ensure that the differences are compared accurately.

Example

See also