Tests: Difference between revisions

Jump to navigation Jump to search
784 bytes added ,  25 June 2012
=Level1= is intended for the page title
(added link for octave manual)
(=Level1= is intended for the page title)
Line 1: Line 1:
Writing tests for function is an important thing that is usually overlooked. It helps a lot in preventing regression. There's a section in the [[http://www.gnu.org/software/octave/doc/interpreter/Test-Functions.html#Test-Functions|octave manual]] for it.
Writing tests for function is an important thing that is usually overlooked. It helps a lot in preventing regression. There's a section in the Octave manual on [http://www.gnu.org/software/octave/doc/interpreter/Test-Functions.html#Test-Functions Test Functions].


= Writing tests =
== Writing tests ==
== in .m files ==
== in .cc files ==
==declaring functions inside a test block==


  function experience
Octave provides for robust testing of functions.  The manual includes a section on the [http://www.gnu.org/software/octave/doc/interpreter/Test-Functions.html#Test-Functions Test Functions].  Several examples are included.
 
===Declaring Functions Inside a Test Block===
 
Octave's ''test'' function automatically inserts the contents of each test block into a function. Although it is admittedly hacky/ugly, this implies that addition functions may be declared within a test block.  For example, the empty function below named {{Codeline|experience}} is accompanied by a single test block which includes two function definitions.
 
  function experience ()
  %!test
  %!test
  %! experience_design_mat
  %! experience_design_mat
Line 24: Line 27:
  %! % endfunction: don't add it here. Let test() do it.
  %! % endfunction: don't add it here. Let test() do it.


= running tests =
== Running Tests ==
== from m files ==
 
== from .cc files ==
Tests are run tests in m-files by using the {{Codeline|test}} function/command.  For example, to test the {{Codeline|experience}} above use the command below.
You can run tests in .cc files by doing something like
 
  test experience
 
Or alternatively, use the functional form
 
  test ("experience")
 
To run tests in .cc files, the path to the file must be provided.
 
   test /full/path/to/file.cc
   test /full/path/to/file.cc
364

edits

Navigation menu