Tests: Difference between revisions

36 bytes added ,  31 July 2017
Small overhauling of this section.
(→‎Writing tests: prettify using syntaxhighlighting.)
(Small overhauling of this section.)
Line 1: Line 1:
Having a thorough [http://en.wikipedia.org/wiki/Test_suite test suite] is
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 {{codeline|test}} function.


== Running tests ==
== Running tests ==


To run all the tests of a specific function, simply use the {{codeline|test}}
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 in
{{codeline|mean()}}:


  >> test mean
  >> test mean
  PASSES 17 out of 17 tests
  PASSES 17 out of 17 tests


These tests are written in the Octave language at the bottom of the
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 file]
which defines {{codeline|mean()}}.  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 ran with:


  >> __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.cc


  test /full/path/to/file.m


== Writing tests ==
== Writing tests ==