I’m pretty a newbie in elixir, was a RoR developer. Now I’m following a practice in Elixir site.
Question:
After first project has build with mix, tested with cmd ‘mix test’ shows “2 tests, 0 failures” even there’s only one assert “assert KV.hello() == :world” in the test script.
Where can I find the other unseen assert?
If it’s vaild that the elixir prefer explicit over implicit, asserts are better to be explicitly explored as well.
When you run mix test --trace you get a more detailed output:
PurlinatorTest
* test doc at Purlinator.hello/0 (1) (0.00ms)
* test greets the world (0.00ms)
Finished in 0.03 seconds
2 tests, 0 failures
Randomized with seed 990227
It shows you the Module of a test (PurlinatorTest in my example) and the name of each test.
This example shows as well, that not every assert has to be directly in the testcode. I do have a test that is displayed as “test doc at Purlinator.hello/0 (1)”, this means that actually the examples from the documentation string for Purlinator.hello/0 was run and its output compared to what is given in the docs. You can disable this behaviour by removing the line doctest Purlinator from a Testmodule.
If you generate the project with mix new, then in the test file, there will be a line like doctest YourProject, that means it will include the test block in the YourProject.ex file, which is the first test in @NobbZ 's trace result. Check the doctest section of official website.