[英]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?当
rebar3
与eunit
参数一起使用时,有没有办法调试 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.