Unit testing: Difference between revisions

m
syntax highlighting fixup automation
(→‎{{header|Ruby}}: Add test::unit)
m (syntax highlighting fixup automation)
Line 18:
Jsish supports an '''internal''' ''-u'' command line option to run unit tests, as part of the base implementation. These tests can include trial inputs and expected outputs in special comment blocks within a source file. Other command line options determine the level of verbosity and logging used when running tests. Being inside comment sections, unit tests do not affect the normal operation of a script (besides the negligible time taken for the interpreter to read in and skip over the comment sections). When in ''-u'' test-mode, source lines starting and ending with semi-colons '';'' are echoed using a special output format that also evaluates the enclosed expression and captures the result.
 
<langsyntaxhighlight lang="javascript">/* A+B in Jsish */
var line = console.input();
var nums = line.match(/^\s*([+-]?[0-9]+)\s+([+-]?[0-9]+)\s*/);
Line 48:
-111
=!EXEPECTEND!=
*/</langsyntaxhighlight>
 
{{out}}
Line 145:
Typical test cases look like:
<langsyntaxhighlight lang="smalltalk">test06b_MiscMath_errors
self should:[ 0 ln ] raise:DomainError.
self should:[ 0 log2 ] raise:DomainError.
Line 162:
n := sqrt := nil.
 
self should:[-10 integerSqrt] raise:DomainError.</langsyntaxhighlight>
 
When executed headless, a result object is returned from a run, which can be printed or further analyzed.
<br>For example:
<langsyntaxhighlight lang="smalltalk">outcome := IntegerTest run.
outcome printCR.
(JSONPrinter encode:outcome) printCR</langsyntaxhighlight>
{{out}}
<pre>97 run, 97 passed, 0 skipped, 0 failed, 0 errors
10,327

edits