Editing Tests
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 26: | Line 26: | ||
See the file test/fntests.log for additional details. | See the file test/fntests.log for additional details. | ||
To run tests in a specific file, one can simply specify the path instead of a function name: | To run tests in a specific file, one can simply specify the path instead of a function name: | ||
Line 34: | Line 32: | ||
== Writing tests == | == Writing tests == | ||
Tests appear as <code>%!</code> blocks at the bottom of the source file, together with <code>%!demo</code> blocks. A typical m function file, will have the following structure: | Tests appear as <code>%!</code> blocks at the bottom of the source file, together with <code>%!demo</code> blocks. A typical m function file, will have the following structure: | ||
Line 101: | Line 97: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
These are actually a shorthand version of {{codeline|%!test assert (foo (bar))}}, and {{codeline|assert}} is simply an Octave function that throws an error when two arguments fail to compare. | These are actually a shorthand version of | ||
{{codeline|%!test assert (foo (bar))}}, and {{codeline|assert}} is simply | |||
an Octave function that throws an error when two arguments fail to compare. | |||
=== Error / Warning === | === Error / Warning === | ||
Line 150: | Line 144: | ||
==== Test for failure ==== | ==== Test for failure ==== | ||
If a warning or error message cannot be tested with one of the single-line tests mentioned above, the {{codeline|fail}} function can be used within a test block | If a warning or error message cannot be tested with one of the single-line tests mentioned above, the {{codeline|fail}} function can be used within a test block verify expected error and warning functionality such as: | ||
<syntaxhighlight lang="Octave"> | <syntaxhighlight lang="Octave"> | ||
Line 187: | Line 181: | ||
%! endfor | %! endfor | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Testing]] | [[Category:Testing]] | ||
[[Category:Development]] | [[Category:Development]] |