Test Cases

Every module whose name ends with a trailing Test and that contains a call to use ExUnit is considered a test case. A test case is essentially a collection of setup callbacks and tests.

The most important thing to know here is that test cases can be executed either concurrently or sequentially in relation to other test cases. All the test cases that use the async: true option in use ExUnit are executed concurrently. Then, the rest of the test cases are executed sequentially (in the order they were defined), by default in random order.

images/test_suite.png

As we mentioned, a test case by itself doesn’t contain any logic. It’s only a container for setup callbacks and tests. The execution of a test case goes like this:

  1. All setup_all callbacks are executed.
  2. All tests are executed with their test-specific setup and teardown callbacks.

Let’s start from setup_all. All setup_all callbacks are executed in the order they’re defined in the test case, and they’re executed in the same process. Essentially, before running any tests, the test case spawns a process, runs all the setup_all callbacks in that process, and then starts running tests.

After the setup_all callbacks, the test case runs tests. Tests inside a single test case are always run sequentially, by default in random order (unless a suite seed is provided). If you’re curious as to why single tests are not run in parallel, the reason is performance: in most cases, single tests are quick enough that the overhead of executing them in parallel and each in its own process is bigger than the time it takes to run the tests.

The only thing left to understand is the life cycle of single tests.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.106.100