Reputation: 4588
I have the following files. If you look in app.ex the doctest says 2 + 2 is 3. I am intentionally trying to make it fail.
app.ex
defmodule App do
@doc """
Adds two numbers
## Examples
iex> App.add(2, 2)
3
"""
def add(a,b) do
a + b
end
end
app_test.exs
defmodule AppTest do
use ExUnit.Case
doctest App
end
In the console I type: mix test
and the result is:
Finished in 0.01 seconds
0 failures
Randomized with seed 547000
Upvotes: 0
Views: 532
Reputation: 9639
The problem seems to be in formatting of your @doc
. I think, the examples to be properly parsed and executed by Doctest, have to be indented with 4 spaces.
I'm pasting your code here with updated formatting for reference:
defmodule App do
@doc """
Adds two numbers
## Examples
iex> App.add(2, 2)
3
"""
def add(a,b) do
a + b
end
end
Upvotes: 3
Reputation: 54684
It seems that mix is not finding any test cases at all, otherwise you would get the message 12 tests, 0 failures
instead of just 0 failures
This probably happens because of the non-standard naming of your test file. In Elixir, test files must end with *_test.exs
, you used *.text.exs
(maybe a typo).
If you rename your test to test/app_test.exs
it should work just fine.
Upvotes: 2