unit testing - Run ExUnit.Case functions serially using Agent -


i know that, default, exunit.case synchronous (according docs http://elixir-lang.org/docs/stable/ex_unit/exunit.case.html). read issue ( https://github.com/elixir-lang/elixir/issues/3580 ) , seems test functions inside case run serially.

when run simple test case without global state cases indeed run serially.

but when use global state agent order of execution depends on luck. same call

mix test --trace 

the order of execution change. here test suite:

defmodule serialtest   use exunit.case    test "1"     agent.update(:card_id, fn nil -> 1 end)     assert true   end    test "2"     res = agent.get(:card_id, fn res -> res end)     assert res == 1   end    test "3"     agent.update(:card_id, fn id -> 3 end)     assert true   end    test "4"     res = agent.get(:card_id, fn res -> res end)     assert res == 3   end end 

sometimes passes not. how can have execution order of functions conform declaration order in file defined using agent's global state?

the tests run serially run in random order. tests failing because order dependent change global state.

when run suite see @ bottom:

randomized seed 596046 

you can disable adding exunit.configure seed: 0 test_helper.exs rather advise tests order independent.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -