有什么更好的方法来生成使用BOOST.Test文件检测报告? [英] What is the better way to generate test report in a file using BOOST.Test?
本文介绍了有什么更好的方法来生成使用BOOST.Test文件检测报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道,在默认情况下报告是针对标准错误,所以人们必须重定向到一个文件中。
我的问题是我们应该做一个全球性的灯具里面呢?这似乎没有工作对我来说一些如何。
I know by default report is directed to standard-error, and so one has to redirect it to a file. My question is shall we do this inside a global fixture? Which isn't seem to be working for me some how.
这是我的尝试 -
struct MyConfig
{
MyConfig()
: testReport("fileName.log")
{
if(!testReport.fail())
original = std::cerr.rdbuf(testReport.rdbuf());
}
~MyConfig()
{
cerr.rdbuf(original);
testReport.close();
}
ofstream testReport;
streambuf* original;
};
BOOST_GLOBAL_FIXTURE(MyConfig);
运行测试后,在控制台上报告仅输出,虽然0KB文件与给定的名称创建。
After running the test, report outputs on console only, though a 0kb file is created with the given name.
推荐答案
您可以试试这个另类,改编自这里并声称在升压1.34.1工作。这似乎更是加速计划 - 看到一个结果流置换器的使用
You could try this alternative, adapted from here and alleged to work on Boost 1.34.1. This seems to be more as Boost intends - see the usage of a results stream overrider.
//
// run_tests.cc
//
#define BOOST_AUTO_TEST_MAIN
#include <iostream>
#include <fstream>
#include <cassert>
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/results_reporter.hpp>
std::ofstream ReportRedirector::out;
struct ReportRedirector
{
ReportRedirector()
{
out.open("fileName.log");
assert( out.is_open() );
boost::unit_test::results_reporter::set_stream(out);
}
private:
static std::ofstream out;
};
BOOST_GLOBAL_FIXTURE(ReportRedirector)
这篇关于有什么更好的方法来生成使用BOOST.Test文件检测报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文