• <legend id='OVlZo'><style id='OVlZo'><dir id='OVlZo'><q id='OVlZo'></q></dir></style></legend>

  • <i id='OVlZo'><tr id='OVlZo'><dt id='OVlZo'><q id='OVlZo'><span id='OVlZo'><b id='OVlZo'><form id='OVlZo'><ins id='OVlZo'></ins><ul id='OVlZo'></ul><sub id='OVlZo'></sub></form><legend id='OVlZo'></legend><bdo id='OVlZo'><pre id='OVlZo'><center id='OVlZo'></center></pre></bdo></b><th id='OVlZo'></th></span></q></dt></tr></i><div id='OVlZo'><tfoot id='OVlZo'></tfoot><dl id='OVlZo'><fieldset id='OVlZo'></fieldset></dl></div>

    <tfoot id='OVlZo'></tfoot>

      <small id='OVlZo'></small><noframes id='OVlZo'>

        • <bdo id='OVlZo'></bdo><ul id='OVlZo'></ul>
      1. Boost.Test:寻找一个有效的非平凡测试套件示例/教程

        Boost.Test: Looking for a working non-Trivial Test Suite Example / Tutorial(Boost.Test:寻找一个有效的非平凡测试套件示例/教程)

          <tfoot id='n5cxB'></tfoot>
          • <bdo id='n5cxB'></bdo><ul id='n5cxB'></ul>

                  <small id='n5cxB'></small><noframes id='n5cxB'>

                  <i id='n5cxB'><tr id='n5cxB'><dt id='n5cxB'><q id='n5cxB'><span id='n5cxB'><b id='n5cxB'><form id='n5cxB'><ins id='n5cxB'></ins><ul id='n5cxB'></ul><sub id='n5cxB'></sub></form><legend id='n5cxB'></legend><bdo id='n5cxB'><pre id='n5cxB'><center id='n5cxB'></center></pre></bdo></b><th id='n5cxB'></th></span></q></dt></tr></i><div id='n5cxB'><tfoot id='n5cxB'></tfoot><dl id='n5cxB'><fieldset id='n5cxB'></fieldset></dl></div>
                  <legend id='n5cxB'><style id='n5cxB'><dir id='n5cxB'><q id='n5cxB'></q></dir></style></legend>
                    <tbody id='n5cxB'></tbody>

                  本文介绍了Boost.Test:寻找一个有效的非平凡测试套件示例/教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Boost.Test 文档 和示例似乎并没有真正包含任何重要的示例,到目前为止我找到的两个教程 此处 和 此处 虽然有帮助,但都是相当基础的.

                  The Boost.Test documentation and examples don't really seem to contain any non-trivial examples and so far the two tutorials I've found here and here while helpful are both fairly basic.

                  我想要一个用于整个项目的主测试套件,同时维护可以独立运行的单元测试和装置的每个模块套件.我还将使用模拟服务器来测试各种网络边缘情况.

                  I would like to have a master test suite for the entire project, while maintaining per module suites of unit tests and fixtures that can be run independently. I'll also be using a mock server to test various networking edge cases.

                  我使用的是 Ubuntu 8.04,但我会以 Linux 或 Windows 为例,因为我正在编写自己的 makefile.

                  I'm on Ubuntu 8.04, but I'll take any example Linux or Windows since I'm writing my own makefiles anyways.

                  编辑

                  作为测试,我做了以下事情:

                  As a test I did the following:

                  // test1.cpp
                  #define BOOST_TEST_MODULE Regression
                  #include <boost/test/included/unit_test.hpp>
                  
                  BOOST_AUTO_TEST_SUITE(test1_suite)
                  
                  BOOST_AUTO_TEST_CASE(Test1)
                  {
                      BOOST_CHECK(2 < 1);
                  }
                  
                  BOOST_AUTO_TEST_SUITE_END()
                  
                  // test2.cpp
                  #include <boost/test/included/unit_test.hpp>
                  
                  BOOST_AUTO_TEST_SUITE(test2_suite)
                  
                  BOOST_AUTO_TEST_CASE(Test1)
                  {
                      BOOST_CHECK(1<2);
                  }
                  
                  BOOST_AUTO_TEST_SUITE_END()
                  

                  然后我编译它:g++ test1.cpp test2.cpp -o tests

                  这给了我关于链接过程中大量多重定义"错误的信息.

                  This gives me about a bazillion "multiple definition of" errors during linking.

                  当所有内容都在一个文件中时,它工作正常.

                  When it's all in a single file it works fine.

                  推荐答案

                  使用 Boost.Test 进行 C++ 单元测试

                  (永久链接:http://web.archive.org/web/20160524135412/http://www.alittlemadness.com/2009/03/31/c-unit-testing-with-boosttest/)

                  以上是一篇精彩的文章,比实际的 Boost 文档要好.

                  The above is a brilliant article and better than the actual Boost documentation.

                  我还写了一个 Perl 脚本,它将自动生成 makefile 和项目来自类名列表的骨架,包括一体机"测试套件和一个独立的测试套件每个班级.它被称为makeSimple 可以下载来自 Sourceforge.net.

                  I also wrote a Perl script which will auto-generate the makefile and project skeleton from a list of class names, including both the "all-in-one" test suite and a stand alone test suite for each class. It's called makeSimple and can be downloaded from Sourceforge.net.

                  我发现的基本问题是,如果您想将测试拆分为多个文件,您必须链接到预编译的测试运行时,而不是使用 Boost.Test 的仅标头"版本.您必须将 #define BOOST_TEST_DYN_LINK 添加到每个文件中,并且在包含 Boost 标头时,例如使用 <boost/test/unit_test.hpp> 而不是 <boost/test/included/unit_test.hpp>.

                  What I found to be the basic problem is that if you want to split your tests into multiple files you have to link against the pre-compiled test runtime and not use the "headers only" version of Boost.Test. You have to add #define BOOST_TEST_DYN_LINK to each file and when including the Boost headers for example use <boost/test/unit_test.hpp> instead of <boost/test/included/unit_test.hpp>.

                  所以要编译为单个测试:

                  So to compile as a single test:

                  g++ test_main.cpp test1.cpp test2.cpp -lboost_unit_test_framework -o tests
                  

                  或编译单个测试:

                  g++ test1.cpp -DSTAND_ALONE -lboost_unit_test_framework -o test1
                  

                  .

                  // test_main.cpp
                  #define BOOST_TEST_DYN_LINK
                  #define BOOST_TEST_MODULE Main
                  #include <boost/test/unit_test.hpp>
                  
                  // test1.cpp
                  #define BOOST_TEST_DYN_LINK
                  #ifdef STAND_ALONE
                  #   define BOOST_TEST_MODULE Main
                  #endif
                  #include <boost/test/unit_test.hpp>
                  
                  BOOST_AUTO_TEST_SUITE(test1_suite)
                  
                  BOOST_AUTO_TEST_CASE(Test1)
                  {
                      BOOST_CHECK(2<1);
                  }
                  
                  BOOST_AUTO_TEST_SUITE_END()
                  
                  // test2.cpp
                  #define BOOST_TEST_DYN_LINK
                  #ifdef STAND_ALONE
                  #   define BOOST_TEST_MODULE Main
                  #endif
                  #include <boost/test/unit_test.hpp>
                  
                  BOOST_AUTO_TEST_SUITE(test2_suite)
                  
                  BOOST_AUTO_TEST_CASE(Test1)
                  {
                      BOOST_CHECK(1<2);
                  }
                  
                  BOOST_AUTO_TEST_SUITE_END()
                  

                  这篇关于Boost.Test:寻找一个有效的非平凡测试套件示例/教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                  Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                  How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                  What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                  Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                  How boost auto-linking makes choice?(boost自动链接如何做出选择?)
                1. <small id='4bA0M'></small><noframes id='4bA0M'>

                  <tfoot id='4bA0M'></tfoot>
                2. <i id='4bA0M'><tr id='4bA0M'><dt id='4bA0M'><q id='4bA0M'><span id='4bA0M'><b id='4bA0M'><form id='4bA0M'><ins id='4bA0M'></ins><ul id='4bA0M'></ul><sub id='4bA0M'></sub></form><legend id='4bA0M'></legend><bdo id='4bA0M'><pre id='4bA0M'><center id='4bA0M'></center></pre></bdo></b><th id='4bA0M'></th></span></q></dt></tr></i><div id='4bA0M'><tfoot id='4bA0M'></tfoot><dl id='4bA0M'><fieldset id='4bA0M'></fieldset></dl></div>

                        <tbody id='4bA0M'></tbody>

                        <bdo id='4bA0M'></bdo><ul id='4bA0M'></ul>
                          • <legend id='4bA0M'><style id='4bA0M'><dir id='4bA0M'><q id='4bA0M'></q></dir></style></legend>