Google 单元测试检查 Table 打印

Google Unit Test to check Table Printing

是否可以使用 google 单元测试来测试 table 用 c++ 打印?

可以用其他单元测试框架来完成吗?

到目前为止,在 SO 的 A quick introduction to the Google C++ Testing Framework I only see test of values. This 问题中讨论了使用 google mock 来测试数组。

我想您可以使用正则表达式来检查格式。 C++11 有一个专门用于此的函数。下面是一个大纲示例,改编自 cplusplus.com,但您可以开发更复杂的解决方案来非常准确地测试 table。

c++11

#include <string>
#include <regex>

std::string s = "|some|sort|of|table|row|"
std::regex r = "" // Matching regex
ASSERT_TRUE(std::regex_match(s, r))

此外,您可以拆分(使用 std::string::find()std::string::substr() 概述 here)table 以使用 ASSERT_EQ(parsed_value, exp_value)

少Objective评论:
我发现 google test 有几乎所有的工具。您提到的价值测试实际上非常通用。 (有点不可避免的)工作是处理可用测试的数据,这意味着推断您关心的数据和特征并将其呈现给 ASSERT_* 和 EXPECT_* 宏。