Is there any way to tell plunit to run a goal before every test or after every test? This is useful for tests that implicitly affect global state, for example when testing predicates that cache results (library(pcre) is one example, where some predicates cache intermediate results using assertz/1).
setup(Goal) option in begin_tests/2, but it runs before any of the tests. (Similarly, begin_tests/2 option
cleanup(Goal) runs after all the tests.)
I want a way of specifying a goal to be run for each test, and not have to specify
setup(Goal) for each test. (Some other language’s unit test frameworks have both global and per-test setup/cleanuyp; SWI-Prolog’s plunit only has global setup/cleanup.)
Do the tests run sequentially or can they run in parallel? I presume that they run sequentially, but this isn’t documented AFAICT. If I want to test that things work properly in a multi-threaded environment (e.g., that caching is done on a per-thread basis or globally), is there any test infrastructure to help this kind of test? I noticed that the code for library(plunit) has
set_test_options([concurrent(true]) but this doesn’t appear in the documentation for set_test_options/1; also, it’s not clear how to specify these options – do I simply add
:- set_test_options([concurrent(true]). to the file?