View Source ExUnitParameterize (ExUnitParameterize v0.1.0-alpha.3)

Parameterized tests for ExUnit.

Provides the parameterized_test macro, implementing test parameterization for ExUnit.

The parameterized_test macro relies on the ExUnit.Case.test macro, and should support all the same use-cases. Please file an issue if you find use-cases of test which parameterized_test doesn't handle.

Examples:

defmodule ParameterizedTest do
  use ExUnit.Case
  import ExUnitParameterize

  parameterized_test "basic test", [
    [a: 1, b: 1, expected: 2],                # basic test[a:1, b:1, expected:2]
    one_plus_two: [a: 1, b: 2, expected: 3],  # basic test[one_plus_two]
    failing_case: [a: 1, b: 2, expected: 4]   # basic test[failing_case]
  ] do
    assert a + b == expected
  end
end

Test naming

By default the string representation of the params will be appended to the test name, unless you provide an explicit name.

For the example above the test names would be:

  • basic test[a: 1, b: 1, expected: 2]
  • basic test[one_plus_two]
  • basic test[failing_case]

In case the name would be longer than the max atom size, the 1-based index will be used.

Summary

Functions

Defines a not implemented parametrized test.

Defines a parameterized test that uses the test context.

Functions

Link to this macro

parameterized_test(message, parameters)

View Source (macro)

Defines a not implemented parametrized test.

See ExUnit.Case.test/1.

Examples:

defmodule NotImplementedCase do
  use ExUnit.Case
  import ExUnitParameterize
  parameterized_test "name", [
    [a: 1],
    [a: 2],
  ]
end
Link to this macro

parameterized_test(message, var \\ quote do _ end, parameters, contents)

View Source (macro)

Defines a parameterized test that uses the test context.

See ExUnit.Case.test/3 and ExUnit.Case#module-context

Examples:

defmodule ParameterizedCaseWithTagsAndContext do
  use ExUnit.Case
  import ExUnitParameterize

  setup do
    {:ok, spam: "spam"}
  end

  @tag foo_tag: "foo"
  @tag :bar_tag
  parameterized_test "basic test with tags and context", context, [
    [a: 1, b: 2, expected: 3],
    [a: 1, b: 2, expected: 4]
  ] do
    assert context[:foo_tag] == "foo"
    assert context[:bar_tag] == true
    assert context[:spam] == "spam"
    assert a + b == expected
  end

end