Unit testing: Difference between revisions
Content added Content deleted
(→Insitux: inclusion) |
|||
Line 21: | Line 21: | ||
For a simple example of the testing process, check out the [[Test_a_function#Go]] task. |
For a simple example of the testing process, check out the [[Test_a_function#Go]] task. |
||
=={{Header|Insitux}}== |
|||
Alongside assertions and mocking available in pure Insitux (see [https://www.rosettacode.org/wiki/Test_a_function#Insitux Test a function]), the Node.js REPL has the ability to generate a code coverage report of unvisited lines and columns, useful for writing thorough unit tests. Here is a basic demonstration: |
|||
<syntaxhighlight lang="insitux"> |
|||
(function subject x y z |
|||
(return-unless (num? x) x) |
|||
(return-unless (num? y) y) |
|||
(if x y z)) |
|||
(assert (= (subject :a 2 3) :a)) |
|||
(assert (= (subject 1 :b 3) :b)) |
|||
(assert (= (subject 1 2 3) 2)) |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
Invoked from the terminal with <code>npx ix . -unv</code>. |
|||
<pre> |
|||
unvisited.txt generated: 1 unvisited (97% coverage) |
|||
true |
|||
</pre> |
|||
<code>unvisited.txt</code>: |
|||
<pre> |
|||
entry.ix 4 11 |
|||
</pre> |
|||
We're being told here that line 4, column 11 has an expression which was not visited at runtime. Through investigation we see that it's impossible for <code>z</code> to be returned, as <code>x</code> must always be a number - an inherently truthy value. |
|||
=={{header|Java}}== |
=={{header|Java}}== |