2

我通过rebar3模板创建了一个简单的应用程序,例如:

apps/myapp/app/myapp_app.erl

-module(myapp_app).

-behaviour(application).

-export([start/2, stop/1]).

start(_StartType, _Params) ->
    ok.

stop(_State) ->
    ok.

我为此写了一个测试:

apps/myapp/test/myapp_test.erl

-module(myapp_test).

-include_lib("eunit/include/eunit.hrl").

simple_test() ->
    myapp_app:start(ok, 42).

可悲的是,当我启动测试时,两个文件之间的链接似乎没有完成:

$ rebar3 eunit
===> Verifying dependencies...
===> Compiling shoreline
===> Performing EUnit tests...
F
Failures:

  1) myapp_test:simple_test/0
     Failure/Error: {error,undef,
                        [{myapp_app,start,"*",[]},
                         {myapp_test,simple_test,0,
                             [{file,
                                  "/.../apps/myapp/test/myapp_test.erl"},
                              {line,8}]},
                         {myapp_test,simple_test,0,[]}]}
     Output:

Finished in 0.074 seconds
1 tests, 1 failures
===> Error running tests

有什么要补充的rebar.config吗?

4

2 回答 2

2

如果您在“src”以外的自定义目录中有 .erl 文件,则需要将其添加到代码路径中。

erl_opts您可以通过修改下面的部分来使用 rebar3 来做到这一点'rebar.config'

{erl_opts, [debug_info, {src_dirs, ["src", "app"]}]}. 

希望这对你有用。

于 2020-03-29T19:44:41.857 回答
1

rebar3如果您.erl一直在/app我将它们移至/src.

➜  myapp rebar3 eunit
===> Verifying dependencies...
===> Compiling myapp
===> Performing EUnit tests...
.
Finished in 0.081 seconds
1 tests, 0 failures
➜  myapp ls
LICENSE      README.md    _build       rebar.config src          test
➜  myapp mv src app
➜  myapp rebar3 eunit
===> Verifying dependencies...
===> Performing EUnit tests...
F
Failures:

  1) myapp_test:simple_test/0: module 'myapp_test'
     Failure/Error: {error,undef,
                           [{myapp_app,start,[ok,42],[]},
                            {myapp_test,simple_test,0,[]}]}
     Output:

Finished in 0.036 seconds
1 tests, 1 failures
===> Error running tests

undef在运行时评估调用时找不到方法。2为了帮助查看rebar3正在做什么,我强烈推荐debug , DEBUG=1.

于 2020-03-29T19:13:23.560 回答