Setup and Teardown

ZUnit runs each of your tests in isolation, to prevent variable and function leakage between tests. You can specify @setup and @teardown functions within your test files, which will be run before and after each test in the file, within the scope of the test, allowing you to set up the environment prior to the test being executed.

@setup

The @setup method is run before each test, and can be used to set environment variables, define functions, or load scripts.

@setup {
  # Load a script to set up the test environment
  load some-setup-script
}

@teardown

The @teardown method is run after each test, and can be used to clean up the environment after a test has finished running.

@teardown {
  # Remove a file generated by the test
  rm some-generated-file
}

Bootstrap Scripts

ZUnit will look in the support directory (tests/_support by default) for a script named bootstrap. If found, this is sourced prior to any tests being run, and affects the global environment for all your tests. This bootstrap script can be used to install software, set environment variables and source programs required for your tests to run.

For an example, check out the bootstrap script for Zulu, which sets up a full embedded environment to run tests against without affecting the user’s shell session.