如何实现测试套件和例升压的组织? [英] How to achieve organisation of test suites and cases with Boost?

查看:103
本文介绍了如何实现测试套件和例升压的组织?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的单元测试和相当新的C ++。最近我一直在使用RSpec的Ruby中使用测试驱动开发的一些经验。现在我正在努力让类似的工作在C ++与Boost的单元测试框架。

I'm new to Unit Testing and rather new to C++. Recently I had some experience with test driven development in Ruby using RSpec. Now I'm trying getting similar working in C++ with Boost's unit testing framework.

我组织在项目的根文件夹下创建一个目录 / src目录应用程序的我的头文件和源文件。正如我多次看到周围在其他的C ++程序,有一个目录 /测试在项目的根目录下的测试似乎是合理的。

I'm organising my header and source files of the application in a directory /src under the project's root folder. As I've seen it multiple times around in other C++ programs, having the tests in a directory /tests in the project's root directory seems reasonable.

现在我要复制的源文件的目录结构,以及在测试中。因此,假设我有以下的源/头文件结构:

Now I want to replicate the directory structure of the source files as well in the tests. Thus, assume I've got the following source/header file structure:

/src
  /controller
    controller_class.h
    controller_class.cpp
  /model
    model_a.h
    model_a.cpp
    model_b.h
    model_b.cpp
  /view
    simple_view.h
    simple_view.cpp

和因此测试被组织起来跟着

And thus the tests are organised as followed

/tests
  TestRunner.cpp
  /controller
    controller_class_test.cpp
  /model
    model_a_test.cpp
    model_b_test.cpp
  /view
    simple_view_test.cpp

对于 TestRunner.cpp 我从的这个博客帖子

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE "MyProgram Unit Tests"
#include <boost/test/unit_test.hpp>

问题

我现在想继续在 TestRunner.cpp 与创建基本的测试套装(用于控制器,模型和视图)如下:

Problem

I now thought to continue in TestRunner.cpp with the creation of the basic test suits (for controller, model and view) as follows

BOOST_AUTO_TEST_SUITE ( controller )
  //some stuff here
BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE ( model )
  //some stuff here
BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE ( view )
  //some stuff here
BOOST_AUTO_TEST_SUITE_END()

欲望

但如何我现在可以进一步嵌套测试套件和案例融入这些顶级测试服?我终于想有实际的测试案例仅出现在 * _ TEST.CPP 文件。虽然每个这些文件的包裹测试用例到一个额外的测试套件:

Desire

But how can I now integrate further nested test suites and cases into these top-level test suits? I finally want to have the actual test cases only appear in the *_test.cpp files. While each of those files wrap the test cases into one additional test suite:


  • 主测试模块( TestRunner.cpp

    • 控制器测试套件( TestRunner.cpp

      • 控制器类测试套件( controller_class_test.cpp

        • 控制器类测试用例( controller_class_test.cpp

        • Master Test Module (TestRunner.cpp)
          • Controller Test Suite (TestRunner.cpp)
            • Controller Class Test Suite (controller_class_test.cpp)
              • Controller Class Test Cases (controller_class_test.cpp)

              • 模型测试套件( model_a_test.cpp

                • A型测试用例( model_a_test.cpp

                • Model A Test Suite (model_a_test.cpp)
                  • Model A Test Cases (model_a_test.cpp)

                  • B型测试用例( model_B_test.cpp

                  • Model B Test Cases (model_B_test.cpp)

                  • 简单查看测试套件( simple_view_test.cpp

                    • 简单查看测试用例( simple_view_test.cpp

                    • Simple View Test Suite (simple_view_test.cpp)
                      • Simple View Test Cases (simple_view_test.cpp)

                      我如何必须包括在各自的更高层次的套房嵌套西装和案例?我找不到Boost文档的任何东西,虽然<一个href=\"http://www.boost.org/doc/libs/1_48_0/libs/test/doc/html/utf/user-guide/test-organization/auto-test-suite.html\">The单元测试框架>用户指南>测试组织>测试套件> 来到pretty关闭自动注册。结果
                      在Ruby中使用RSpec一位刚刚需要将测试文件(阅读: * _ spec.rb )我做的方式和通过他们自动遍历。我想,以加速我不得不明确声明它的方式。

                      How do I have to include the nested suits and cases in the respective higher level suite? I could not find anything in the Boost documentation, though The Unit Test Framework > User's guide > Test organization > Test suite > Automated registration came pretty close.
                      In Ruby with RSpec one just needs to place the test files (read: *_spec.rb) the way I did and its automatically iterating through them. I guess, with Boost I have to explicitly declare it that way.

                      推荐答案

                      Boost.Test测试套件类似于C ++的命名空间。您可以重新启动他们的任何时间。每个测试文件的只需要放置测试用例正确的测试套件:

                      Boost.Test test suites are similar to C++ namespaces. You can restart them any time. Each of your test files just need to place test cases in correct test suites:

                      controller_class_a_test.cpp:
                      
                       BOOST_AUTO_TEST_SUITE( controller )
                      
                       BOOST_AUTO_TEST_CASE( test_class_a )
                       {
                       }
                      
                       BOOST_AUTO_TEST_SUITE_END()
                      
                      
                      controller_class_b_test.cpp:
                      
                       BOOST_AUTO_TEST_SUITE( controller )
                      
                       BOOST_AUTO_TEST_CASE( test_class_b )
                       {
                       }
                      
                       BOOST_AUTO_TEST_SUITE_END()
                      

                      同样的概念也适用于任何深度的测试树。同时你并不需要顶级TestRunner.cpp可言。只是所有测试文件合并成一个单一的测试模块和Boost.Test约需其余的照顾。

                      The same concept applies to the test tree of any depth. Also you do not need top level TestRunner.cpp at all. Just combine all your test files into a single test module and Boost.Test will take care about the rest.

                      这篇关于如何实现测试套件和例升压的组织?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆