为什么“开始(不)调试”(F5和Ctrl + F5)都不会创建CppUnit * .xml报告文件?

时间:2012-07-31 19:14:30

标签: c++ unit-testing visual-studio-2005 cppunit

首先,我想欢迎所有人参与stackoverflow,因为这是我的第一个问题 我在使用Visual Studio 2005上的CppUnit生成输出* .xml文件时遇到困难。当我使用F5或Ctrl + F5运行代码(开始调试或启动无调试)时,它不会创建报告文件。但是当我“手动”(通过/ debug中的* .exe文件)运行它时,会创建报告文件。可能是什么原因?

testApp.cpp:

#include "Test_myFuzzy.h"

#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/XmlOutputter.h>

int main(){
    CppUnit::TextUi::TestRunner runner;

    std::ofstream ofs("tests.xml"); 
    CppUnit::XmlOutputter* xml = new CppUnit::XmlOutputter(&runner.result(),ofs); 
    xml->setStyleSheet("report.xsl");
    runner.setOutputter(xml);

    runner.addTest(Test_myFuzzy::suite());
    runner.run();

    return 0;
}

感谢您的回答!

1 个答案:

答案 0 :(得分:0)

std::ofstream ofs("tests.xml"); 

您没有指定应该在哪里创建test.xml文件。因此,默认情况下,它将在exe所在的同一文件夹中创建。

解决此问题的一种方法是指定创建/查找文件"C:\test.xml"的位置,或者在项目文件夹中搜索,因为该文件可能是在调试仓中创建的。