简体   繁体   English

如何使用 rebar3 使用适当的代码设置测试?

[英]How to setup tests with the appropriate code using rebar3?

I have created a simple application via rebar3 templates such as:我通过rebar3模板创建了一个简单的应用程序,例如:

apps/myapp/app/myapp_app.erl

-module(myapp_app).

-behaviour(application).

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

start(_StartType, _Params) ->
    ok.

stop(_State) ->
    ok.

I have written a test for that:我为此编写了一个测试:

apps/myapp/test/myapp_test.erl

-module(myapp_test).

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

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

Sadly, when I launch the test, it seems that the link is not done between the two files:可悲的是,当我启动测试时,似乎两个文件之间没有建立链接:

$ 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

Is there something to add in rebar.config ?rebar.config有什么要添加的吗?

If you have .erl files in a custom directory other than 'src', then you need to add it to the code path.如果在“src”以外的自定义目录中有 .erl 文件,则需要将其添加到代码路径中。

You can do it using rebar3 by modifying erl_opts section in 'rebar.config' as below.您可以通过修改'rebar.config' erl_opts部分来使用 rebar3,如下所示。

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

Hope this can work for you.希望这对你有用。

rebar3 does not find your .erl files if you have been under /app I moved them to /src . 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 means could not be found when evaluating the call at runtime. undef表示在运行时评估调用时找不到 2 To help see what rebar3 is doing I can highly recommend debug , DEBUG=1 . 2为了帮助了解rebar3正在做什么,我强烈推荐debug , DEBUG=1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用TFS 2010中的构建设置测试 - How to setup tests using builds in TFS 2010 如何使用unittest从测试或setUp内部停止所有测试? - How to stop all tests from inside a test or setUp using unittest? React Native:如何设置自动集成测试? - React Native: How to setup automated integration tests? 自动测试从设置中列出的代码中抛出错误,尽管它已在其他测试中正确执行 - Automated tests throwing error from code listed in setup despite it having already executed correctly in other tests 您如何为 Capacitor 原生应用设置自动化测试? - How do you setup automated-tests for Capacitor native apps? 如何组织实时数据完整性测试和代码单元测试? - How to organize live data integrity tests and code unit tests? 如何在VS Code中调试nightwatch测试 - How to debug nightwatch tests in VS Code Selenium自动化测试如何实际设置为在敏捷软件过程之后在公司中运行? - How are Selenium automation tests actually setup to run in company following an agile software process? 我如何外部化我的硒设置以使我的硒测试可配置 - How can I externalise my selenium setup in order to make my selenium tests configurable 如何为模块内的所有测试定义设置和拆除 - How can I define a setup and tear down for all tests inside a module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM