From 9fd0ef2e2a94456528b7ee9a226b9497bf8d98f1 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 10 Sep 2016 20:56:41 -0500 Subject: [PATCH] Add Run ExUnit Tests In A Deterministic Order as an elixir til --- README.md | 3 +- ...n-exunit-tests-in-a-deterministic-order.md | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 elixir/run-exunit-tests-in-a-deterministic-order.md diff --git a/README.md b/README.md index e1405c2..c47d042 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really warrant a full blog post. These are mostly things I learn by pairing with smart people at [Hashrocket](http://hashrocket.com/). -_468 TILs and counting..._ +_469 TILs and counting..._ --- @@ -98,6 +98,7 @@ _468 TILs and counting..._ - [Quitting IEx](elixir/quitting-iex.md) - [Replace Duplicates In A Keyword List](elixir/replace-duplicates-in-a-keyword-list.md) - [Reversing A List](elixir/reversing-a-list.md) +- [Run ExUnit Tests In A Deterministic Order](elixir/run-exunit-tests-in-a-deterministic-order.md) - [String Interpolation With Just About Anything](elixir/string-interpolation-with-just-about-anything.md) - [Updating Values In A Map](elixir/updating-values-in-a-map.md) - [Word Lists For Atoms](elixir/word-lists-for-atoms.md) diff --git a/elixir/run-exunit-tests-in-a-deterministic-order.md b/elixir/run-exunit-tests-in-a-deterministic-order.md new file mode 100644 index 0000000..90ace7b --- /dev/null +++ b/elixir/run-exunit-tests-in-a-deterministic-order.md @@ -0,0 +1,29 @@ +# Run ExUnit Tests In A Deterministic Order + +When running a file of +[`ExUnit`](http://elixir-lang.org/docs/stable/ex_unit/ExUnit.html) tests, +they will be executed in a pseudo-random order based on a seed value. In +general, `ExUnit` will pick a random seed each time you run your tests. If +you'd like to add some determinism to the order that your tests run in, you +can specify the seed in the `ExUnit` configuration. + +```elixir +ExUnit.configure seed: 42 +ExUnit.start + +defmodule AssertionTest do + use ExUnit.Case, async: true + + test "the truth" do + assert true + end + + test "more truth" do + assert 2 + 2 = 4 + end +end +``` + +[source](https://til.hashrocket.com/posts/4a7dc5fd94-run-exunit-tests-in-the-order-they-are-defined) + +h/t Chris Erin