1,855
edits
(→Writing tests: prettify using syntaxhighlighting.) |
(Small overhauling of this section.) |
||
Line 1: | Line 1: | ||
Having a thorough [ | Having a thorough [https://en.wikipedia.org/wiki/Test_suite test suite] is something very important which is usually overlooked. It is an incredible help in preventing regression bugs and quickly assess the status of old code. For example, many packages in Octave Forge become deprecated after losing their maintainer simply because they have no test suite. | ||
something very important which is usually overlooked. It is an incredible | |||
help in preventing regression bugs and quickly assess the status of old code. | |||
For example, many packages in Octave Forge become deprecated after losing | |||
their maintainer simply because they have no test suite. | |||
GNU Octave has multiple tools that help in creating a comprehensive test | GNU Octave has multiple tools that help in creating a comprehensive test suite, accessible to both developers and end-users, as detailed on the [http://www.gnu.org/software/octave/doc/interpreter/Test-Functions.html Octave manual]. Basically, test blocks are {{codeline|%!test}} comment blocks, typically at the end of a source file, which are ignored by the Octave interpreter and only read by the {{manual|test}} function. | ||
suite, accessible to both developers and end-users, as detailed on the | |||
[http://www.gnu.org/software/octave/doc/interpreter/Test-Functions.html Octave manual]. | |||
Basically, test blocks are {{codeline|%!test}} comment blocks, typically at the | |||
end of a source file, which are ignored by the Octave interpreter and only | |||
read by the {{ | |||
== Running tests == | == Running tests == | ||
To run all the tests of a specific function, simply use the {{ | To run all the tests of a specific function, simply use the {{manual|test}} command at the Octave prompt. For example, to run the tests of the Octave function {{manual|mean}} type: | ||
command at the Octave prompt. For example, to run the tests | |||
{{ | |||
>> test mean | >> test mean | ||
PASSES 17 out of 17 tests | PASSES 17 out of 17 tests | ||
These tests are written in the Octave language | These tests are written in the Octave language [http://hg.savannah.gnu.org/hgweb/octave/file/6443693a176f/scripts/statistics/base/mean.m#l130 at the bottom of <code>mean.m</code>] which defines the {{manual|mean}} function. It is important that these tests are also available for the end users so they can test the status of their installation. The whole Octave test suite can be run with: | ||
[http://hg.savannah.gnu.org/hgweb/octave/file/6443693a176f/scripts/statistics/base/mean.m#l130 m | |||
which defines {{ | |||
also available for the end users so they can test the status of their | |||
installation. The whole Octave test suite can be | |||
>> __run_test_suite__ | >> __run_test_suite__ | ||
Line 42: | Line 27: | ||
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 | To run tests in a specific file, one can simply specify the path instead of a function name: | ||
a function name: | |||
test /full/path/to/file.m | |||
== Writing tests == | == Writing tests == |