Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang EUnit test module that depends on a library application

I have a medium-sized release with a handful of applications. I recently refactored some common functionality out into a library application within the release. This made my EUnit tests fail with undef messages whenever testing anything that required the library application.

The set up is something like this:

% In apps/utils/src/utils.erl
-module(utils).

-export([foo/0]).

foo() -> "OH HAI".

Then

% In apps/some_app/src/some_app.erl
-module(some_app).

-export([bar/0]).

bar() -> io:format("foo: ~s~n", [utils:foo()]).

% unit tests for bar()

Then the unit tests for some_app:bar() fail. I'm running them with rebar eunit skip_deps=true. I'm using skip_deps=true because my release uses some 3rd party applications (SQL, etc).

I assume that the tests start failing because EUnit is invoking the app under test without its dependencies? Is there any way to fix this? I have configured the .app file to explicitly declare the dependency. It works fine in the release, and it's been deployed for about a day now with no problem, but I'll feel a lot better if I can get the tests to pass again :)

(I could use a mocking app to stub out utils:foo/0, and I can see where that would be ideal idiomatically, but that seems like overkill in this case because utils:foo/0 (read: it's real-world counterpart) does some really simple stuff.)

like image 720
dantswain Avatar asked Nov 09 '12 15:11

dantswain


1 Answers

I was able to get this to work by doing rebar compile eunit skip_deps=true.

The key is to have the compile in there and I have no idea why. I'm guessing that the compile step gets all of the modules into memory. I'd love to hear a good explanation.

like image 160
dantswain Avatar answered Oct 06 '22 21:10

dantswain