Mix test reports 2 tests while there's 1 assert

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.

Thanks from S.Korea.

1 Like

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.

1 Like

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.

1 Like

Based on this thread, I have just changed Elixir master to report doctests separately from tests. So now we will see:

~/OSS/plug[master %]$ mix test
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................

Finished in 3.0 seconds
58 doctests, 389 tests, 0 failures
20 Likes

Hah, awesome! :slight_smile:

2 Likes

Thanks for the great responses!

1 Like