我有一个正在测试的组件:
namespace myproj {
class MyComp {
public:
void doSome();
};
}
using namespace myproj;
void MyComp::doSome() {
// Some code...
// And in the end, for debugging purposes, I print in one of the streams
EV_DEBUG << "Some debugging info" << endl;
}
我的单元测试
我的测试是普通的OmNET++ Unit Test使用 opp_test
工具:
%description:
Tests my component
%includes:
#include "myproj/MyComp.h"
%global:
using namespace ::inet::test::myproj;
%activity:
MyCompTest test = MyCompTest();
test.testDoSome();
EV << ".\n";
%contains: stdout
my test out
当然是一类MyCompTest
正在使用 MyComp
为了运行一些最终会调用 MyComp::doSome
的逻辑.
请注意 testDoSome
将导致打印字符串“my test out”。
问题
问题是,正因为如此 EV_DEBUG
(如果我将其更改为 EV_INFO
, EV_DETAIL
和所有其他 EV
s)在我的原始类(源/模拟代码)中,测试输出中毒,最终输出是:
Some debugging info
my test out
这使得测试失败。如果我注释掉 EV_DEBUG << ...
那么测试就可以了。
如何解决这个问题?我真的必须删除所有 EV
吗?在我的原始代码中打印输出?
最佳答案
您可以通过在 %activity
部分添加这些行来关闭 EV_DEBUG
的打印:
#undef EV_DEBUG
#define EV_DEBUG true ? EV : EV
关于c++ - EV 打印使 INET/OmNET++ 中的单元测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42096671/