[英]How to setup tests with the appropriate code using rebar3?
我通過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
有什么要添加的嗎?
如果在“src”以外的自定義目錄中有 .erl 文件,則需要將其添加到代碼路徑中。
您可以通過修改'rebar.config'
erl_opts
部分來使用 rebar3,如下所示。
{erl_opts, [debug_info, {src_dirs, ["src", "app"]}]}.
希望這對你有用。
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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.