Unit testing with plunit
The SWI Prolog unit testing library supports different ways of defining unit tests for your programs. It has been integrated into KnowRob to facilitate testing using commandline scripts.
Defining tests
While tests can also be defined inline in the same file, it is recommended to add a separate file with the unit tests. Those files have the same name as the Prolog file to be tested, but the extension '*.plt' instead of '*.pl'. Please have a look at the plunit documentation for details on how to define tests in these files. Examples of test files can be found e.g. in the packages comp_temporal or knowrob_map_tools.
Since KnowRob predicates usually operate on OWL datastructures, their proper workings can only be examined if appropriate test data is available. It may therefore make sense to create an OWL file in the owl/ subfolder that provides example data for testing.
Running tests for KnowRob packages
The script rosprolog-test starts KnowRob using the specified package and runs all tests that have been defined for that package. Note that Prolog is in this case started using the -q (–quiet) argument that suppresses all output during startup, so you will only see errors, warnings or, in case all tests succeed, one dot per test performed.
rosrun rosprolog rosprolog-test <your-pkg>