PlUnit is designed to cooperate with the assertion/1
test provided by library(debug).3This
integration was suggested by Günter Kniesel. If an
assertion fails in the context of a test, the test framework reports
this and considers the test failed, but does not trap the debugger.
in the test-body is attractive for two scenarios:
- Confirm that multiple claims hold. Where multiple claims about
variable bindings can be tested using the == option in the test header,
arbitrary boolean tests, notably about the state of the database, are
harder to combine. Simply adding them in the body of the test has two
disadvantages: it is less obvious to distinguish the tested code from
the test and if one of the tests fails there is no easy way to find out
- Testing‘scenarios' or sequences of actions. If one step in
such a sequence fails there is again no easy way to find out which one.
By inserting assertions into the sequence this becomes obvious.
Below is a simple example, showing two failing assertions. The first
line of the failure message gives the test. The second reports the
location of the assertion.4If
known. The location is determined by analysing the stack. The second
failure shows a case where this does not work because last-call
optimization has already removed the context of the test-body.
If the assertion call originates from a different file this is reported
appropriately. The last line gives the actually failed goal.
A is 2^3,
assertion(A == 9).
% PL-Unit: test
test a: assertion at line 7 failed
test a: assertion failed
% 2 assertions failed