For faster navigation, this Iframe is preloading the Wikiwand page for विकिपीडिया:Template sandbox and test cases.

विकिपीडिया:Template sandbox and test cases

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 cases to prevent bugs.

For what kind of templates

[संपादित करें]

It is recommended to apply the test case pattern to templates using ParserFunctions 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.

Any template that is transcluded in thousands of pages should of course be tested before an edit is made.

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

Furthermore, the template should not have too many interleaving <includeonly> and <noinclude> blocks. Ideally there is only one <noinclude> block, placed at the bottom of the template, and containing the ((documentation)) template.

How to create /sandbox and /testcases 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 these subpages are present, the green /doc box produced by ((documentation)) automatically provide links to them. Note that "/sandbox" and "/testcases" are spelled in all lower-case.

2: Copy only the code (everything that is not surrounded by <noinclude>) from your Template:X to Template:X/sandbox. And add the following at the end of the last line, in the same line:

<noinclude>

((template sandbox notice))
</noinclude>

In other words, the result should be:

[-- Template code --]<noinclude>

((template sandbox notice))
</noinclude>

Note! The template code must start directly before and touch the <noinclude> tag. Any blank space or newlines between the template code and the <noinclude> tag can cause the template to render unwanted spaces or newlines when used.

3: Copy a few transcluding examples from articles (((X | .... ))) to your Template:X/testcases. In the test case subpage, duplicate each example, and for one copy of each example, replace X with X/sandbox. This is done so that you may compare the old and new outputs side by side in the future. Lastly, add the following line at the beginning of the test case page. It does not matter how many blank lines you put around it:

((template test cases notice))

4: Thus Template:X/testcases will look like this:

 ((template test cases notice))

 ((X | foo))
 ((X/sandbox | foo))

 ((X | bar))
 ((X/sandbox | bar))

4b: To make differences easier to identify, you can use Template:Testcase to lay out your test cases. Then, test cases which are changed in the sandbox are highlighted so you can double check that the change was intentional.

How to use them subsequently

[संपादित करें]
  • Sync sandbox from the real template (i.e. step 2 above)
  • Have fun editing the sandbox
  • Verify the test cases
  • If everything looks good, copy the code from the sandbox to the real template

If you chose not to compare the new and old outputs side by side described at the last bullet point of the previous section, 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.

Test with other users - ((test-mode))

[संपादित करें]

If you are satisfied with the changes that you made in the sandbox version, and with what the test cases show - you might consider trying ((test-mode)). This will enable several users to browse pages on Wikipedia with the test version of your template, and yet not affect anyone else displaying those pages.

  • Wikipedia:High-risk templates
  • ((template sandbox notice)) – To put at the bottom of /sandbox pages.
  • ((template test cases notice)) – To put on top of /testcases pages.
  • ((test-mode)) - allow editors with "test-mode" on to display wikipedia pages with test template instead of public template.
{{bottomLinkPreText}} {{bottomLinkText}}
विकिपीडिया:Template sandbox and test cases
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?