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
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: