简体   繁体   English

使用 rebar3 时如何调试运行的 Eunit 测试套件?

[英]How to debug my Eunit test suite run when using rebar3?

I have created an release app with rebar3 (beta-4).我用 rebar3 (beta-4) 创建了一个release应用程序。 Added some eunit tests and wrote some code.添加了一些 eunit 测试并编写了一些代码。

For now I have to debug one test case to see what I have to add to make the implementation to work properly.现在我必须调试一个测试用例,看看我必须添加什么才能使实现正常工作。

I found some articles about using dbg from Erlang console and I found how to write debug info from Eunit.我从 Erlang 控制台找到了一些关于使用dbg的文章,并且找到了如何从 Eunit 编写调试信息。 But I need to get info from code that I have to test (the actual implementation(logic)).但是我需要从我必须测试的代码中获取信息(实际实现(逻辑))。

Is there a way to debug Erlang code (actual source code, not the test one) when rebar3 is used with eunit argument?rebar3eunit参数一起使用时,有没有办法调试 Erlang 代码(实际源代码,而不是测试代码)?

I'm using tracing in terminal like there: https://aloiroberto.wordpress.com/2009/02/23/tracing-erlang-functions/我在终端中使用跟踪: https ://aloiroberto.wordpress.com/2009/02/23/tracing-erlang-functions/

One way to do this is use rebar3 to run a shell under the test profile, then start the debugger and set up your breakpoints and such:一种方法是使用rebar3在测试配置文件下运行 shell,然后启动调试器并设置断点等:

$ rebar3 as test shell
...
1> debugger:start().
{ok, <0.67.0>}

This will pop up the debugger GUI .这将弹出 调试器 GUI Once the debugger is set up and ready, run your test under eunit :调试器设置并准备就绪后,在eunit下运行测试:

2> eunit:test(your_test_module,[verbose]).
======================== EUnit ========================
your_test_module: xyz_test_ (module 'your_test_module')...

Assuming you set up a suitable breakpoint in the debugger, this will hit it, but you'll likely run into a problem with this approach: by default, eunit tests time out after 5 seconds, which doesn't give you much time for debugging.假设您在调试器中设置了一个合适的断点,这将命中它,但您可能会遇到这种方法的问题:默认情况下, eunit测试在 5 秒后超时,这不会给您太多时间进行调试. You need to specify a longer timeout for your test, which is why the example above shows that what's running is a test fixture named xyz_test_ , which wraps the actual test with a long timeout.您需要为测试指定更长的超时时间,这就是为什么上面的示例显示正在运行的是名为xyz_test_测试夹具,它用较长的超时时间包装实际测试。 Such a fixture is pretty simple:这样的夹具非常简单:

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

xyz_test_() ->
    {timeout,3600,
     [fun() -> ?assertMatch(expected_value, my_module:my_fun()), ok end]}.

Here, the actual test is the anonymous function, which matches the return value from my_module:my_fun/0 , which for this example represents the business logic under test.在这里,实际测试是匿名函数,它与my_module:my_fun/0的返回值相匹配,在这个例子中它代表被测试的业务逻辑。 This example fixture sets the test timeout to one hour;此示例夹具将测试超时设置为一小时; you can of course set it as needed for your application.您当然可以根据应用程序的需要进行设置。

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

相关问题 如何使用 erlang 插件在 vscode 中调试 rebar3 erlang? - How do I debug rebar3 erlang in vscode with the erlang plugin? 单例并在测试中运行时如何调试WCF调用 - How to debug a WCF call when it's a singleton and being run in a test 使用 dotnet run 时如何调试 .NET 核心控制台应用程序 - How to Debug a .NET Core Console App When Using dotnet run Eclipse-调试通过GNU Make启动的测试套件 - Eclipse - debug a test suite launched through GNU Make 单元测试在调试时通过但在运行时失败 - Unit test passes when in debug but fails when run 如何在使用 Mocha 运行的 Eclipse 中调试 Javascript 单元测试? - How do I Debug a Javascript Unit Test in Eclipse that is Run with Mocha? 单元测试通过调试,但在运行时挂起 - Unit-test passes in Debug, but hangs when Run 为什么我的Selenium测试代码可以单步成功运行,但是在使用“运行”时却失败? - Why my Selenium test code run successfully in single-step but failed when using Run? 如何防止预期异常破坏调试测试运行? - How to prevent expected exceptions from breaking the debug test run? 如何才能在DEBUG模式下运行单元测试? - How can I make a unit test run in DEBUG mode only?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM