Where to put test file for eunit?

643 Views Asked by At

I'm trying to test function that loads file from disk and do some manipulation on it. I have my project divided into src/ and test/ directories. I put test file under test/ directory and tried to run unit test that loads this file. However file seems to be not visible when running test from IDE (IntelliJ) or console using rebar.

$ ./rebar eunit
==> traffic-emas (eunit)
input_test: load_from_file_test...*failed*
in function input:load_intersection_definition/1 (src/input.erl, line 40)
in call from input_test:load_from_file_test/0 (test/input_test.erl, line 14)
**error:{badmatch,{error,enoent}}

Where should I put test files for eunit to make it visible?

2

There are 2 best solutions below

0
On BEST ANSWER

You can print out the working directory in your eunit tests and see where it thinks it's running:

debugVal(file:get_cwd())

That should give you a good idea of where to put it.

1
On

Rebar's documentation suggests that you should be placing a module-specific eunit tests inside the module itself. E.g.:

-ifdef(TEST).

simple_test() ->
    ok = application:start(myapp),
    ?assertNot(undefined == whereis(myapp_sup)).

-endif.