4

I wrote a few tests for my Elixir project and put them in the test/ directory. Now that I run mix test, I get:

$ mix test
Test patterns did not match any file: 

That's it, there's nothing after that. Do I have to manually set the path for my tests? A quick Google search did not reveal anything.


This is what all of my tests look like:

# project_dir/test/my_app/some_module.exs

defmodule MyApp.SomeModule.Test do
  use ExUnit.Case
  doctest MyApp.SomeModule

  test "method 1" do
    assert MyApp.SomeModule.method_1_works?
  end

  test "method 2" do
    assert MyApp.SomeModule.method_2_works?
  end
end 
Sheharyar
  • 73,588
  • 21
  • 168
  • 215

1 Answers1

7

All tests are supposed to end with _test.exs. Renaming my tests from some_module.exs to some_module_test.exs fixed it, and now it works.

From $ mix help test:

This task starts the current application, loads up test/test_helper.exs and then requires all files matching the test/**/_test.exs pattern in parallel.


I'd still like to know if it's possible to manually configure test paths (even if the word 'test' doesn't come at the end).

Sheharyar
  • 73,588
  • 21
  • 168
  • 215
  • 1
    Yes, it is possible - run `mix help test` and see block Configuration. `:test_paths` - list of paths containing test files, defaults to `["test"]`. It is expected all test paths to contain a `test_helper.exs` file. `:test_pattern` - a pattern to load test files, defaults to `*_test.exs`. – Oleksandr Avoiants Sep 29 '16 at 20:56
  • 1
    Is there a reason why you want to change the test path rather than using the default? Running `mix new` should give you a good scaffold. Unless there's a compelling reason why you need to have your files not end in *_test.exs, I think it's better to stay with the default. Keeping it idiomatic and all that – Kevin Sep 29 '16 at 22:15