使用rebar3时如何调试我的Eunit测试套件运行? [英] How to debug my Eunit test suite run when using rebar3?

查看:223
本文介绍了使用rebar3时如何调试我的Eunit测试套件运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用rebar3(beta-4)创建了一个release应用程序. 添加了一些eunit测试并编写了一些代码.

I have created an release app with rebar3 (beta-4). Added some eunit tests and wrote some code.

目前,我必须调试一个测试用例,以查看必须添加哪些内容才能使实现正常工作.

For now I have to debug one test case to see what I have to add to make the implementation to work properly.

我从Erlang控制台中找到了一些有关使用dbg的文章,并且找到了如何从Eunit编写调试信息.但是我需要从必须测试的代码(实际实现(逻辑))中获取信息.

I found some articles about using dbg from Erlang console and I found how to write debug info from Eunit. But I need to get info from code that I have to test (the actual implementation(logic)).

rebar3eunit参数一起使用时,是否可以调试Erlang代码(实际源代码,而不是测试代码)?

Is there a way to debug Erlang code (actual source code, not the test one) when rebar3 is used with eunit argument?

我正在终端中使用跟踪,例如: https://aloiroberto.wordpress.com/2009/02/23/tracing-erlang-functions/

I'm using tracing in terminal like there: https://aloiroberto.wordpress.com/2009/02/23/tracing-erlang-functions/

推荐答案

一种方法是使用rebar3在测试配置文件下运行Shell,然后启动调试器并设置断点,诸如此类:

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 as test shell
...
1> debugger:start().
{ok, <0.67.0>}

这将弹出调试器GUI .调试器设置好并准备就绪后,在eunit下运行测试:

This will pop up the debugger GUI. Once the debugger is set up and ready, run your test under eunit:

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

假设您在调试器中设置了合适的断点,就会遇到问题,但是您可能会遇到这种方法的问题:默认情况下,eunit会在5秒钟后测试超时,这不会您花了很多时间进行调试.您需要为测试指定更长的超时时间,这就是为什么上面的示例显示正在运行的是名为xyz_test_测试治具,这包装了长时间的实际测试.这样的装置非常简单:

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. 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. 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]}.

在这里,实际的测试是匿名函数,该函数与my_module:my_fun/0的返回值匹配,在本示例中,该返回值表示正在测试的业务逻辑.这个示例夹具将测试超时设置为一小时;您当然可以根据需要为应用程序进行设置.

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. This example fixture sets the test timeout to one hour; you can of course set it as needed for your application.

这篇关于使用rebar3时如何调试我的Eunit测试套件运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆