Difference between revisions of "Unit Testing"

From WormBaseWiki
Jump to navigationJump to search
(Created page with 'TODO')
 
(Basic unit testing description.)
Line 1: Line 1:
TODO
+
=== Executing Unit Tests ===
 +
 
 +
# change directory into your [https://github.com/WormBase/website Github Website] clone.
 +
# run tests of the REST API: <code>perl t/rest.t</code>
 +
# run tests of the WormBase Perl API: <code>API_TESTS=1 perl t/api.t</code>
 +
 
 +
'''Successful tests''' are preceded by an "ok". For example:
 +
 
 +
<pre>
 +
ok 1 - require 't/rest_tests/template.t';
 +
    ok 1 - port open
 +
    1..1
 +
ok 2 - test_port_open
 +
</pre>
 +
 
 +
'''How to read the output:''' The first "ok 1" means that the first executed test <code>require ...</code> completed sucessfully. "ok 2" shows that the second test was also successful, where sub-tests (i.e., tests within the <code>test_port_open</code> Perl sub) are shown ''above'' as indented lines. The interval "1..1" denotes the tests were run within <code>test_port_open</code>.
 +
 
 +
'''Failed tests''' are preceded by a "not ok" and a short description is displayed that explains why the test failed (lines preceded by "#"). For example:
 +
 
 +
<pre>
 +
    not ok 1 - port open
 +
    #  Failed test 'port open'
 +
    #  at t/rest_tests/template.t line 53.
 +
    #          got: undef
 +
    #    expected: anything else
 +
    1..1
 +
    # Looks like you failed 1 test of 1.
 +
not ok 2 - test_port_open
 +
</pre>
 +
 
 +
=== Unit Testing Framework: How it works / Write your own ===
 +
 
 +
Unit tests are
 +
 
 +
* based on [http://perldoc.perl.org/Test/More.html Test::More].
 +
* run on a fully populated WormBase database backend.
 +
* start (and stop) a Catalyst web server (random port between 28,000 and 31,999)
 +
 
 +
'''Unit test templates''' are available as
 +
 
 +
* <code>t/rest_tests/template.t</code> for writing REST API tests
 +
* <code>t/api_tests/template.t</code> for writing WormBase Perl API tests
 +
 
 +
'''New unit tests''' should be using the following workflow:
 +
 
 +
# create a copy of <code>template.t</code> within the same directory; choose a descriptive filename
 +
# make appropriate changes to the newly created file

Revision as of 13:49, 18 June 2013

Executing Unit Tests

  1. change directory into your Github Website clone.
  2. run tests of the REST API: perl t/rest.t
  3. run tests of the WormBase Perl API: API_TESTS=1 perl t/api.t

Successful tests are preceded by an "ok". For example:

ok 1 - require 't/rest_tests/template.t';
    ok 1 - port open
    1..1
ok 2 - test_port_open

How to read the output: The first "ok 1" means that the first executed test require ... completed sucessfully. "ok 2" shows that the second test was also successful, where sub-tests (i.e., tests within the test_port_open Perl sub) are shown above as indented lines. The interval "1..1" denotes the tests were run within test_port_open.

Failed tests are preceded by a "not ok" and a short description is displayed that explains why the test failed (lines preceded by "#"). For example:

    not ok 1 - port open
    #   Failed test 'port open'
    #   at t/rest_tests/template.t line 53.
    #          got: undef
    #     expected: anything else
    1..1
    # Looks like you failed 1 test of 1.
not ok 2 - test_port_open

Unit Testing Framework: How it works / Write your own

Unit tests are

  • based on Test::More.
  • run on a fully populated WormBase database backend.
  • start (and stop) a Catalyst web server (random port between 28,000 and 31,999)

Unit test templates are available as

  • t/rest_tests/template.t for writing REST API tests
  • t/api_tests/template.t for writing WormBase Perl API tests

New unit tests should be using the following workflow:

  1. create a copy of template.t within the same directory; choose a descriptive filename
  2. make appropriate changes to the newly created file