ExUnit v1.6.5 ExUnit View Source
Unit testing framework for Elixir.
A basic setup for ExUnit is shown below:
# File: assertion_test.exs # 1) Start ExUnit. ExUnit.start() # 2) Create a new test module (test case) and use "ExUnit.Case". defmodule AssertionTest do # 3) Notice we pass "async: true", this runs the test case # concurrently with other test cases. The individual tests # within each test case are still run serially. use ExUnit.Case, async: true # 4) Use the "test" macro instead of "def" for clarity. test "the truth" do assert true end end
To run the tests above, run the file using
elixir from the
command line. Assuming you named the file
you can run it as:
ExUnit.Assertions module contains a set of macros to
generate assertions with appropriate error messages.
Mix is the project management and build tool for Elixir. Invoking
from the command line will run the tests in each file matching the pattern
*_test.exs found in the
test directory of your project.
You must create a
test_helper.exs file inside the
test directory and put the code common to all tests there.
The minimum example of a
test_helper.exs file would be:
# test/test_helper.exs ExUnit.start()
Mix will load the
test_helper.exs file before executing the tests.
It is not necessary to
test_helper.exs file in your test
Mix.Tasks.Test for more information.
Link to this section Summary
Returns ExUnit configuration
Returns the pluralization for
Starts ExUnit and automatically runs tests right before the VM terminates
Link to this section Types
Link to this section Functions
ExUnit supports the following options:
:assert_receive_timeout- the timeout to be used on
assert_receivecalls, defaults to
:autorun- if ExUnit should run by default on exit. Defaults to
:capture_log- if ExUnit should default to keeping track of log messages and print them on test failure. Can be overridden for individual tests via
@tag capture_log: false. Defaults to
:colors- a keyword list of colors to be used by some formatters. The only option so far is
[enabled: boolean]which defaults to
:exclude- specifies which tests are run by skipping tests that match the filter;
:formatters- the formatters that will print results, defaults to
:include- specifies which tests are run by skipping tests that do not match the filter. Keep in mind that all tests are included by default, so unless they are excluded first, the
:includeoption has no effect. To only run the tests that match the
:includefilter, exclude the
:testtag first (see the documentation for
ExUnit.Casefor more information on tags);
:max_cases- maximum number of tests to run in parallel. Only tests from different modules run in parallel. It defaults to
System.schedulers_online * 2to optimize both CPU-bound and IO-bound tests;
:module_load_timeout- the timeout to be used when loading a test module, defaults to
:refute_receive_timeout- the timeout to be used on
refute_receivecalls, defaults to
:seed- an integer seed value to randomize the test suite. This seed is also mixed with the test module and name to create a new unique seed on every test, which is automatically fed into the
:randmodule. This provides randomness between tests, but predictable and reproducible results;
:slowest- prints timing information for the N slowest tests. Running ExUnit with slow test reporting automatically runs in
tracemode. It is disabled by default;
:stacktrace_depth- configures the stacktrace depth to be used on formatting and reporters, defaults to
:timeout- sets the timeout for the tests, defaults to
:trace- sets ExUnit into trace mode, this sets
1and prints each test case and test while running. Note that in trace mode test timeouts will be ignored.
Returns the pluralization for
If one is not registered, returns the word appended with an “s”.
If one is already registered, it is replaced.
Runs the tests. It is invoked automatically
if ExUnit is started via
Returns a map containing the total number of tests, the number of failures and the number of skipped tests.
Starts ExUnit and automatically runs tests right before the VM terminates.
If you want to run tests manually, you can set the
false and use
run/0 to run tests.