Expectations by jaycfields

expectations

adding signal, removing noise

Run Custom Functions Before Running the Test Suite

As of version 1.4.24, expectations will execute any function that includes the following metadata {:expectations-options :before-run}, before starting to execute the test suite.

There are several reasons that you might want to call a custom function before the test suite is executed-

  • load sample data to a database
  • delete a temp directory
  • replace logging with standard out or /dev/null

The following example should serve as a decent reference on how to add your own 'before-run' functions.

Run Custom Functions After Completing the Test Suite

As of version 1.4.48, expectations will execute any function that includes the following metadata {:expectations-options :after-run}, after executing the test suite.

This can be used to clean up resources and shut down executors or other services after the test suite has completed.

expectations-options

These functions can be defined anywhere; however, expectations looks in a default location for a configuration file. If expectations finds this configuration file it removes (what should be) the namespace and requires it with :reload. As a result, this configuration namespace will be removed and redefined with each expectations suite run.

The name of this default configuration file is expectations_options.clj (thus the namespace is expectations-options). Expectations looks for this file in the root test directory. If you have :test-paths ["test/clojure"] in your project.clj, then you'll want to create test/clojure/expectations_options.clj.

If you place your expectations_options.clj file in the correct location and you add the {:expectations-options :before-run} or {:expectations-options :after-run} metadata to a function in the expectations-options namespace, your function should be run automatically the next time your test suite runs. You may want to start with a (println) just to verify that things are going as you expect.