-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sometimes you want to run the same tests but with different parameters. In ExUnit, it is possible to do so by passing a `:parameterize` key to `ExUnit.Case`. The value must be a list of maps which will be the parameters merged into the test context. For example, Elixir has a module called `Registry`, which can have type `:unique` or `:duplicate`, and can control its concurrency factor using the `:partitions` option. If you have a number of tests that *behave the same* across all of those values, you can parameterize those tests with: use ExUnit.Case, async: true, parameterize: for(kind <- [:unique, :duplicate], partitions <- [1, 8], do: %{kind: kind, partitions: partitions}) Then, in your tests, you can access the parameters as part of the context: test "starts a registry", %{kind: kind, partitions: partitions} do ... end Use parameterized tests with care: * Although parameterized tests run concurrently when `async: true` is also given, abuse of parameterized tests may make your test suite slower * If you use parameterized tests and then find yourself adding conditionals in your tests to deal with different parameters, then parameterized tests may be the wrong solution to your problem. Consider creating separated tests and sharing logic between them using regular functions
- Loading branch information
Showing
10 changed files
with
929 additions
and
861 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.