Previous: PlUnit Running the Test-Suite, Up: lib-plunit [Contents][Index]
Most applications do not want the test-suite to end up in the
final application. There are several ways to achieve this. One way
is to place all tests in separate files and not to load the tests
when creating the production environment. Another way is to wrap
each unit test box in a pair of :- if(…)
, :- endif
directives.
For example, the test could be whether the plunit
module has been
loaded:
:- if(current_module(plunit)). :- begin_tests(Unit[,Options]). … :- end_tests(Unit). :- endif.
Alternatively, you can reserve a system property
e.g. enable_unit_tests
to control whether unit tests should be
enabled. The property is enabled if you run SICStus Prolog as:
% sicstus -Denable_unit_tests=true
Then your Prolog source file could have the structure:
:- use_module(library(system), [environ/2]). … :- if(environ(enable_unit_tests, true)). :- use_module(library(plunit)). :- begin_tests(Unit[,Options]) … :- end_tests(Unit) :- endif.