|
|
豪气的打火机 · nacos常见问题之开启鉴权后客户端报403 ...· 1 月前 · |
|
|
面冷心慈的弓箭 · 在背景同步處理和更新 PWA - ...· 1 月前 · |
|
|
风流的开水瓶 · intellij idea ...· 1 月前 · |
|
|
聪明的冰棍 · DevTools (Microsoft ...· 1 月前 · |
|
|
拉风的猕猴桃 · 黄宗泽|香港男星|明星个人资料_星娱闪耀明星经纪· 3 周前 · |
|
|
愤怒的豆芽 · Apache Kyuubi 在 T3 ...· 1 月前 · |
|
|
打酱油的香蕉 · 中大聯合書院與蔡冠深基金會合辦「音樂聚會系列 ...· 3 月前 · |
|
|
斯文的酱肘子 · 最硬核的背景设定知识补全:《狼与香辛料》—— ...· 1 年前 · |
|
|
睿智的松鼠 · 2012年度国家科学技术进步奖获奖项目 ...· 1 年前 · |
我使用 谷歌C++测试框架 对代码进行单元测试。我使用 带C++单元测试模块的Eclipse 进行输出分析。
以前我使用过 CppUnit ,它有宏家族 消息 ,可以这样调用:
CPPUNIT_ASSERT_EQUAL_MESSAGE("message",EXPECTED_VALUE,ACTUAL_VALUE)
并允许发送自定义消息来测试输出。
有办法在google测试输出中包含一些自定义文本吗?
(最好是将消息包含到现有程序读取的数据中,以便使用google测试进行自动单元测试。)
gtest宏返回一个流,用于在测试失败时输出诊断消息。
EXPECT_TRUE(false) << "diagnostic message";
在当前版本的gtest中,没有办法干净地这样做。我查看了代码,如果测试失败,将显示唯一的文本输出(包装在gtest“Messages”中)。
但是,在某个时候,gtest开始对屏幕进行
printf
'ing,您可以利用上面的级别获得与平台无关的颜色。
这里有一个被黑的宏来做你想做的事。这使用了最普通的内部文本着色。当然,
internal::
名称空间应该会敲响警钟,但是它可以工作。
用法:
TEST(pa_acq,Foo)
// C style
PRINTF("Hello world \n");
// or C++ style
TEST_COUT << "Hello world" << std::endl;
}
输出:
代码:
namespace testing
namespace internal
enum GTestColor {
COLOR_DEFAULT,
COLOR_RED,
COLOR_GREEN,
COLOR_YELLOW
extern void ColoredPrintf(GTestColor color, const char* fmt, ...);
#define PRINTF(...) do { testing::internal::ColoredPrintf(testing::internal::COLOR_GREEN, "[ ] "); testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, __VA_ARGS__); } while(0)
// C++ stream interface
class TestCout : public std::stringstream
public:
~TestCout()
PRINTF("%s",str().c_str());
#define TEST_COUT TestCout()
您应该定义如下:
static class LOGOUT {
public:
LOGOUT() {}
std::ostream& info() {
std::cout << "[info ] ";
return std::cout;
} logout;
使用此方法:
logout.info() << "test: " << "log" << std::endl;
请参考Mark Lakata的回答,这是我的方法:
gtest_cout.h
Step1:创建一个头文件,例如:Step1
代码:
#ifndef _GTEST_COUT_H_
#define _GTEST_COUT_H_
#include "gtest/gtest.h"
namespace testing
namespace internal
enum GTestColor
COLOR_DEFAULT, COLOR_RED, COLOR_GREEN, COLOR_YELLOW
extern void ColoredPrintf(GTestColor color, const char* fmt, ...);
#define GOUT(STREAM) \
std::stringstream ss; \
ss << STREAM << std::endl; \
testing::internal::ColoredPrintf(testing::internal::COLOR_GREEN, "[ ] "); \
testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, ss.str().c_str()); \
} while (false); \
|
|
聪明的冰棍 · DevTools (Microsoft Edge 109) 中的新增功能 - Microsoft Edge Developer documentation | Microsoft Learn 1 月前 |
|
|
拉风的猕猴桃 · 黄宗泽|香港男星|明星个人资料_星娱闪耀明星经纪 3 周前 |