7.20 Writing Tests

SWI-Prolog includes the ‘PlUnit’ unit testing framework1, in which you write unit tests in special blocks of Prolog code enclosed within the directives begin_tests/1 and end_tests/1. To insert a new block of unit tests (also known as a test-set) in a Prolog buffer, use the command M-x sweeprolog-plunit-testset-skeleton RET.

Command: sweeprolog-plunit-testset-skeleton

Insert a ‘PlUnit’ test-set skeleton at point.

This command prompts for a name to give the new test-set and inserts a template such as the following:

:- begin_tests(foo_regression_tests).

test() :- TestBody.

:- end_tests(foo_regression_tests).

The cursor is left between the parentheses of the test() head term, and the TestBody variable is marked as a hole (see Holes). To insert another unit test, place point after a complete test case and type C-M-m (or M-RET) to invoke sweeprolog-insert-term-dwim (see Context-Based Term Insertion).


Footnotes

(1)

See Prolog Unit Tests in the SWI-Prolog manual.