Pre/Post test hooks.
When running unit tests you may need to do some preparatory and/or cleanup work.
When running unit tests you may need to do some preparatory and/or cleanup work.
Ideally this should be in the setupAll and tearDownAll methods in your unit tests.
If that isn't possible, then Critical Test allows you to specify hooks that are run before and after the unit tests are run.
The Critical Test hooks are particularly useful for starting/stopping services (a database, docker container etc) before/after you run your unit tests.
A hook can be any executable such as a DCli (Dart), Bash script, CMD ....
To create a hook, create a critical_test directory under your project's 'tool' directory
tool\critical_test
pre_hooks are run before the unit tests start. post_hooks are run after all unit tests have been completed.
Pre/Post hooks will also run when you use the --single switch.
You can suppress hooks by passing in the --no-hooks flag.
cd <myproject>/tool
mkdir critical_test
mkdir critical_test/pre_hook
mkdir critical_test/post_hook
touch critical_test/pre_hook/dostuff.sh
chmod +x critical_test/pre_hook/dostuff.shHooks are sorted alphanumerically so you can prefix the hook's name with a number if you need to control the order the hooks run in.
Last updated
Was this helpful?