Quantcast
Channel: Bartek's coding blog
Viewing all articles
Browse latest Browse all 325

Boost Test Library

$
0
0
www.boost.org/doc/libs/1_52_0/libs/test/

In this short post I would like to describe some basic things related to Unit testing and the Boost Test library. In ideal world every class/function/module should be covered with some test case, but as we all know we do not live in utopia :) Unit tests are also not so easy to introduce, especially when you have some legacy code.

Header and lib version

Boost UTF (Unit Testing Framework) can be used as a header only or as a compiled library. The whole framework consists of almost hounded source files so for long term usage it is better to compile it and link it with your code. You can create static or dynamic library.
Another interesting option is to have a separate test runner that calls your test cases and outputs the log message. Usually your app will be created as a DLL and then called by the framework.

Basic macros

BOOST_WARN(condition)    - level - warning only
BOOST_CHECK(condition) - level - error message, continues the test
BOOST_REQUIRE(condition) - level - error message, stops the test execution
Above there are basic tools for unit tests in Boost. Warn, Check and Require.
BOOST_level_MESSAGE(message)
Displys additional message in case of failure.
BOOST_level_EQUAL(valueA, valueB)
Checks if valueA == valueB, useful for integer values
BOOST_level_EQUAL_COLLECTIONS(startA, endA, startB, endB)
Checks if a whole range of some two collections are equal. Useful for comparing result set with the desired output.
BOOST_level_CLOSE(valueA, valueB, epsilon)
Checks if abs(valueA - valueB) < epsilon, useful for floating point values
BOOST_ERROR(msg)
Displays error message and continues execution. Useful when a condition is made of several sub-conditions.
BOOST_FAIL(message)
Displys error message and stops execution. Useful when a condition is made of several sub-conditions.

Links

Bonus: post published in Vienna :D

Viewing all articles
Browse latest Browse all 325

Trending Articles