我想使用 gtest 添加一个单元测试来测试我的代码是否可以生成与引用文件相同的文件。 gtest 是否具有获取两个文件并进行比较的功能?
最佳答案
Does gtest has a function to take two files and compare them?
没有,gtest中没有这样的函数。
您可以将生成的文件读入 std::string
,并将该文件与您在测试用例中声明的文件进行比较:
std::ifstream t("generated_file.txt");
std::string genfile((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
std::string expectedOutput = R"xxx(Expected
output
goes
here
verbatim
)xxx";
ASSERT_EQUAL(expectedOutput,genfile);
关于c++ - gtest 是否支持文件比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48589258/