Unit testing: Difference between revisions

Line 57:
123 -234
-111</pre>
 
=={{header|jq}}==
jq was developed with unit testing, and the jq source includes a suite of unit tests that utilize the --run-tests option of the jq command. This option expects unit tests to be presented in the form of "paragraphs" that may be specified in one or more files, which by convention have ".test" as the filename suffix.
 
Here is an example of such a .test file with explanatory comments, followed by a transcript showing how it is used and the output that is produced.
 
'''Unit Test File'''
<pre>
# unit-tests.test
# Basic tests are groups of three lines: program, input, expected output
# Blank lines and lines starting with # are ignored
# For example:
 
true
null
true
 
# Failure tests begin with a %%FAIL line, followed by the program and the expected error message.
# %%FAIL tests have no input line.
%%FAIL
{(0):1}
jq: error: Cannot use number (0) as object key at <top-level>, line 1:
 
# Testing the testing apparatus:
length
"This should generate an error"
0
</pre>
'''Transcript'''
<pre>
$ jq --run-tests unit-tests.test
Testing 'true' at line number 5
Testing '{(0):1}' at line number 12
Testing 'length' at line number 16
*** Expected 0, but got 29 for test at line number 18: length
2 of 3 tests passed (0 malformed)
</pre>
 
=={{header|Julia}}==
2,512

edits