类,BOOST_TEST_MODULE,BOOST_AUTO_TEST_SUITE:命名问题
class, BOOST_TEST_MODULE, BOOST_AUTO_TEST_SUITE: problems from naming?
因此,我已经开始使用boost单元测试。当我尝试构建一个创建类实例的简单测试时,我会遇到编译错误。它在没有类实例的情况下运行良好。
编译错误消息为:
/src/test/WTFomgFail_test.cpp: In member function ‘void WTFomgFail::defaultConstructor::test_method()’:
/src/test/WTFomgFail_test.cpp:20: error: expected primary-expression before ‘obj’
/src/test/WTFomgFail_test.cpp:20: error: expected `;' before ‘obj’
WTFomgFail_test.cpp:
#include "WTFomgFail.hpp"
#define BOOST_TEST_MODULE WTFomgFail
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(WTFomgFail)
BOOST_AUTO_TEST_CASE( defaultConstructor )
{
WTFomgFail obj = WTFomgFail();
BOOST_MESSAGE("wow, you did it");
}
BOOST_AUTO_TEST_SUITE_END()
WTFomgFail.hpp:
#ifndef WTFOMGFAIL_HPP_
#define WTFOMGFAIL_HPP_
class WTFomgFail
{
public:
WTFomgFail();
~WTFomgFail();
};
#endif /* WTFOMGFAIL_HPP_ */
WTFomgFail.cpp:
#include "WTFomgFail.hpp"
WTFomgFail::WTFomgFail()
{
}
WTFomgFail::~WTFomgFail()
{
}
如果我将BOOST_AUTO_TEST_SUITE(WTFomgFail)
更改为其他内容,比如BOOST_AUTO_TEST_SUITE(OMGreally)
,错误就会消失。
此外,当使用#define BOOST_TEST_MODULE OMGreally
和BOOST_AUTO_TEST_SUITE(OMGreally)
时,我没有得到错误。
所以,我的问题是,当使用boost UTF时,将模块、testronguite和类命名为明确禁止的相同内容?
我知道我来晚了,但我只是偶然发现了它,它看起来很孤独。。。
要理解此限制,您必须了解Boost Tests最初是如何工作的。(它仍然可以这样工作,但当时没有BOOST_AUTO_...
宏,必须这样做。)
来自文档:
class test_class {
public:
void test_method1()
{
BOOST_CHECK( true /* test assertion */ );
}
void test_method2()
{
BOOST_CHECK( false /* test assertion */ );
}
};
//____________________________________________________________________________//
test_suite*
init_unit_test_suite( int argc, char* argv[] )
{
boost::shared_ptr<test_class> tester( new test_class );
framework::master_test_suite().
add( BOOST_TEST_CASE( boost::bind( &test_class::test_method1, tester )));
framework::master_test_suite().
add( BOOST_TEST_CASE( boost::bind( &test_class::test_method2, tester )));
return 0;
}
这有点麻烦,因为每次添加测试函数时,都必须在两个不同的位置更改代码(函数的定义和向测试套件注册)。注册也有点不直观。
这就是为什么他们推出了BOOST_AUTO_TEST_SUITE
和BOOST_AUTO_TEST_CASE
,它们正在为您做这件事。
传递给BOOST_AUTO_TEST_SUITE
的参数当然是类的名称(上面的test_class
)。BOOST_AUTO_TEST_CASE
的参数是测试函数的名称(上面的test_method1()
和test_method2()
)。
所以不,这些可能(当然)与您正在测试的类和函数不相同。您可以为此使用名称空间,但就我个人而言,我更喜欢简单地将类名后缀为Tu
(如果您不喜欢CamelCase命名,则为_tu
),并将其用于测试套件。
我希望这能有所帮助。
- Boost.TEST with CLion: "Test framework quit unexpectedly"
- 使用 C++ Boost.Test 组织单元测试?
- Boost.Test - 如何在交叉点上检查两个向量
- 在 Boost.Test 中异常时双倍释放
- 数据集(和样本)何时在 boost::test 中销毁?
- 抑制boost.test中的退出信号
- 静态链接再次链接boost.test和cmake在Windows上的mingw
- 我应该使用boost.test分别测试不同类别的类别
- Boost.Test 显示测试持续时间
- 在哪里可以找到Eclipse中解析的Boost.Test输出
- 在BOOST test中添加测试套件而不是测试用例
- GCC 地址清理器 - 将库功能列入黑名单(特别是 boost::test)
- Debugging Boost.Test in Eclipse:debugger 不会在断点处停止
- Boost.Test Custom Type using decorator boost::unit_test::tol
- Boost.Test 使用正则表达式测试文件内容
- 如何将Boost.Test输出记录到HRF中的stdout和XML中的文件中
- 为什么我不能在 Boost.Test 测试用例中创建线程?
- Boost.Test吐出垃圾,而不是可读的错误消息
- Boost.test cannot find main
- Boost Test Boost _CHECK_EQUAL,类型可转换为数组