faq.qbk 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. [/
  2. / Copyright (c) 2003 Boost.Test contributors
  3. /
  4. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. /]
  7. [section:section_faq Frequently Asked Questions]
  8. [h3 Where the latest version of the Boost Test Library is located?]
  9. The latest version of Boost Test Library is available online at [@http://www.boost.org/libs/test].
  10. [h3 I found a bug. Where can I report it?]
  11. You can send a bug report to the boost users' mailing list and/or fill a ticket here [@https://svn.boost.org/trac/boost/].
  12. [h3 I have a request for a new feature. Where can I ask for it?]
  13. You can send a request to the boost developers' mailing list and/or and/or fill a ticket here [@https://svn.boost.org/trac/boost/].
  14. [h3 How to create test case using the Unit Test Framework?]
  15. To create a test case, use the macro
  16. __BOOST_AUTO_TEST_CASE__( test_function );
  17. For more details see the Unit Test Framework __BOOST_AUTO_TEST_CASE__ documentation.
  18. [h3 How to create test suite using the Unit Test Framework?]
  19. To create a test suite use the macro
  20. __BOOST_AUTO_TEST_SUITE__( suite_name );
  21. For more details see the Unit Test Framework __BOOST_AUTO_TEST_SUITE__ documentation.
  22. [h3 Why did I get a linker error when compiling my test program?]
  23. Boost Test Library components provide several usage variants: to create a test program you can
  24. link with the one of the precompiled library variants or use header-only variant. For example, to use Unit Test
  25. Framework you may either include
  26. ``
  27. #include <boost/test/unit_test.hpp>
  28. ``
  29. and link with ``libunit_test_framework.lib`` or you can include
  30. ``
  31. #include <boost/test/included/unit_test.hpp>
  32. ``
  33. in which case you should not need to link with any pre-compiled component. Note also that
  34. you should strictly follow specification on initialization function in other case some compilers may produce linker
  35. error like this.
  36. ``
  37. Unresolved external init_unit_test_suite(int, char**).
  38. ``
  39. The reason for this error is that in your implementation you should specify second argument of
  40. `init_unit_test_suite` exactly as in the specification, i.e.: `char* []`.
  41. [h3 How can I redirect testing output?]
  42. Use ``unit_test_log::instance().set_log_output( std::ostream & )``
  43. For more details see the __UTF__ __output_test_stream_tool__ documentation.
  44. [h3 I want different default log trace level]
  45. Use environment variable __BOOST_TEST_LOG_LEVEL__ to define desired log trace level. You still will be able to reset
  46. this value from the command line. For the list of acceptable values see the __UTF__
  47. __runtime_configuration__ documentation.
  48. [h3 Is there DLL version of Boost.Test components available on Win32 platform?]
  49. Yes. Starting with Boost 1.34.0.
  50. [h3 How to set up a CMake project using __UTF__ (extended)]
  51. Suppose, you are building a test module from one translation unit `test_file.cpp`. First, let's do it using the [link boost_test.usage_variants.single_header header-only usage variant] of the __UTF__.
  52. Let's paste the following content in a `CMakeLists.txt`
  53. at the same location than our test file `test_file.cpp`:
  54. [pre
  55. cmake_minimum_required(VERSION 2.8.7)
  56. project(my_first_test)
  57. enable_testing()
  58. # indicates the location of the boost installation tree.
  59. # hard-coded for our simple example.
  60. set(BOOST_INCLUDE_DIRS $boost_installation_prefix/include)
  61. # creates the executable
  62. add_executable(test_executable test_file.cpp)
  63. # indicates the include paths
  64. target_include_directories(test_executable PRIVATE ${BOOST_INCLUDE_DIRS})
  65. # declares a test with our executable
  66. add_test(NAME test1 COMMAND test_executable)
  67. ]
  68. We will now create the build directory for this project (separate directory),
  69. configure and build the project, as follow:
  70. ```
  71. > cd ``$``test_path
  72. > mkdir build /*< we create a directory dedicated to the build, to avoid
  73. any pollution of the sources with the temporary
  74. build files >*/
  75. > cd build
  76. > cmake .. /*< configuration of the project >*/
  77. > cmake --build . /*< this command builds the project, cmake drives a native
  78. tool that is configured on the previous command line >*/
  79. > ctest /*< runs the tests declared in the project and prints a report >*/
  80. ```
  81. In the case you are using the [link boost_test.usage_variants.shared_lib shared libraries] variant of __UTF__,
  82. some modifications should be done in your CMakeLists.txt.
  83. [pre
  84. cmake_minimum_required(VERSION 2.8.11)
  85. project(my_first_test)
  86. enable_testing()
  87. # replace XX with the version you have
  88. set(Boost_ADDITIONAL_VERSIONS "1.XX" "1.XX.0")
  89. # finds boost, triggers an error otherwise
  90. find_package(Boost XX REQUIRED COMPONENTS unit_test_framework)
  91. # creates the executable
  92. add_executable(test_executable test_file.cpp)
  93. # indicates the include paths
  94. target_include_directories(test_executable PRIVATE ${Boost_INCLUDE_DIRS})
  95. # indicates the shared library variant
  96. target_compile_definitions(test_executable PRIVATE "BOOST_TEST_DYN_LINK=1")
  97. # indicates the link paths
  98. target_link_libraries(test_executable ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
  99. # declares a test with our executable
  100. add_test(NAME test1 COMMAND test_executable)
  101. ]
  102. We will now create the build directory for this project (separate directory), configure and build the project,
  103. as follow:
  104. ```
  105. > cd ``$``test_path
  106. > mkdir build /*< we create a directory dedicated to the build, to avoid any pollution of the sources with the temporary
  107. build files >*/
  108. > cd build
  109. > cmake -DBOOST_ROOT=``$``boost_installation_prefix .. /*< configuration of the project, the `BOOST_ROOT` configuration element indicates the
  110. Boost module of `cmake` where to find our installation >*/
  111. > cmake --build . /*< this command builds the project, cmake drives a native tool that is configured on the
  112. previous command line >*/
  113. > ctest /*< runs the tests declared in the project and prints a report >*/
  114. ```
  115. [endsect] [/faq]