C++ C+中的Google单元测试+;:如何编写持久数据文件?

C++ C+中的Google单元测试+;:如何编写持久数据文件?,c++,unit-testing,persistence,googletest,file-writing,C++,Unit Testing,Persistence,Googletest,File Writing,问题: 1)通过C++谷歌单元测试创建的文件是哪里? < P > 2)有没有一种方法在C++谷歌单元测试中编写持久数据文件,这样文件在测试运行后是可访问的? 代码和所需行为 我正在用catkin_make在Ubuntu14.04上运行单元测试。我希望代码在某个地方编写一个文件,以便在测试运行后找到它。下面的代码编写了一个文件,但我不知道它去了哪里,或者在单元测试完成后它是否仍然存在 TEST(GUnitTestFileIo, Test_One) { std::ofstream csvFil

问题:

1)通过C++谷歌单元测试创建的文件是哪里?

< P > 2)有没有一种方法在C++谷歌单元测试中编写持久数据文件,这样文件在测试运行后是可访问的? 代码和所需行为

我正在用catkin_make在Ubuntu14.04上运行单元测试。我希望代码在某个地方编写一个文件,以便在测试运行后找到它。下面的代码编写了一个文件,但我不知道它去了哪里,或者在单元测试完成后它是否仍然存在

TEST(GUnitTestFileIo, Test_One)
{
  std::ofstream csvFile;
  csvFile.open("helloWorldTestFile.csv");
  if (csvFile.is_open()) {
    csvFile << "Hello, World, !" << std::endl;
    csvFile.close();
  } else {
    std::cout << "Failed to open the file!" << std::endl;
  }
}

int main(int argc, char **argv){
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
TEST(gunitestfileio,TEST_One)
{
std::流csvFile;
打开(“helloWorldTestFile.csv”);
if(csvFile.is_open()){

csvFile一种解决方案是简单地写入绝对文件路径。以下代码从google单元测试内部将文件写入用户的主目录:

TEST(GUnitTestFileIo, Test_One)
{
  char const* tmp = getenv( "HOME" );
  if ( tmp == NULL ) {
    std::cout << "$(HOME) environment variable is not defined!";
  } else {
    std::string home( tmp );  // string for the home directory
    std::ofstream csvFile;  // write the file
    csvFile.open(home + "/helloWorldTestFile.csv");
    if (csvFile.is_open()) {
      csvFile << "Hello, World, !" << std::endl;
      csvFile.close();
    } else {
      std::cout << "Failed to open the file!" << std::endl;
    }
  }
}

// Run all the tests that were declared with TEST()
int main(int argc, char **argv){
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
TEST(gunitestfileio,TEST_One)
{
char const*tmp=getenv(“主”);
if(tmp==NULL){

std::cout问题寻求调试帮助(“为什么此代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现问题所需的最短代码。没有明确问题说明的问题对其他读者没有用。请参阅:如何创建。使用“编辑”链接以改进您的问题-不要通过评论添加更多信息。谢谢!您只是含糊地解释了您实施的内容。很难说这里发生了什么。从这个意义上说:如果您可以浓缩一个小的(但有效的)内容,请尝试包含您正在执行的操作的所有相关信息的示例。这在很大程度上取决于您如何调用生成的可执行文件。是否是MSVC集成?CTest?自己运行它?