c++ - EV 打印使 INET/OmNET++ 中的单元测试失败

标签 c++ unit-testing omnet++ inet

我有一个正在测试的组件:

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_INFOEV_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/

相关文章:

在另一个类中使用抽象类对象的 C++ 设计模式

c++ - 在 C++17 中 i++ + i++ 会评估什么?

c++ - STL 容器有单元测试吗?

c++ - Omnet++:作为复合模块的子模块调用时找不到类

omnet++ - 静脉中的单播通信

c++ - 仅使用其他两个数字达到目标数字

unit-testing - 如何测试Go中的数据库错误?

java - 模拟测试澄清

c++ - 调试来自同一代码库的运行时差异

c++ - 错误 : request for member (maybe you meant to use '->' ? ) 已经使用 '->'