为什么两个"Start (Without) Debugging"(F5 和 Ctrl+F5)都不创建 CppUnit *.xml 报告文件?

Why both "Start (Without) Debugging" (F5 anf Ctrl+F5) doesn't create CppUnit *.xml report file?

本文关键字:CppUnit 创建 报告 文件 xml F5 两个 Start Without 为什么 Debugging      更新时间:2023-10-16

首先,我想欢迎大家加入stackoverflow,因为这是我的第一个问题
我在VisualStudio2005上使用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;
}

谢谢你的回答!

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

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

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