Issue by TheoVerhelst
Tuesday Feb 16, 2016 at 23:50 GMT
Originally opened as https://github.com/ulb-infof209/Group5/pull/35
In order to compile the project with this commit, you have to install the Boost unit test framework on your computer.
Each class has now a corresponding unit test source file — off course, the tests are not yet written.
You can divide your test in multiple test cases, for example you can write one test case per method of your class. Each test case is defined like this:
BOOST_AUTO_TEST_CASE(RelevantTestCaseName)
{
// Insert code here
}
You can only test public methods of the class. If you must test some private methods, a good idea would be to move these private methods in a new class as public methods (this is what I read on SO mainly, I think this is a good habit).
The Boost unit test works with a system of fixture. A fixture is a context in which the tests will be executed. You can add public attributes to the fixture, such as
struct MyClassTestsFixture
{
size_t myArraySize{20};
};
and myArraySize will be available as-is in the test cases code, as if you were writing the code of a method of the fixture. Usually the fixture has at least one attribute, an instance of the tested class.
As well you can use the constructor of the fixture in order to do more complicated context initialization.
Boost give us some macro to perform various forms of checks, I listed some of these here:
BOOST_CHECK();
BOOST_CHECK_EQUAL();
BOOST_REQUIRE();
BOOST_REQUIRE_EQUAL();
BOOST_CHECK tests the expression, and if it is false, it logs it and then continues.
BOOST_REQUIRE tests the expression, and if this is false, it stops the current test case. This is used when the following code have no sense if the expression is false.
*_EQUAL should be used to check equality between two expressions rather than using == because it display useful debug info on the values if the test fails. Note that this variant can be used only if both expressions can be printed with std::cout (I don't think this is noted in the Boost doc, but I saw this when compiling my tests on another project).
TODO:
TheoVerhelst included the following code: https://github.com/ulb-infof209/Group5/pull/35/commits
Tuesday Feb 16, 2016 at 23:50 GMT
Originally opened as https://github.com/ulb-infof209/Group5/pull/35
In order to compile the project with this commit, you have to install the Boost unit test framework on your computer.
Each class has now a corresponding unit test source file — off course, the tests are not yet written.
You can divide your test in multiple test cases, for example you can write one test case per method of your class. Each test case is defined like this:
You can only test public methods of the class. If you must test some private methods, a good idea would be to move these private methods in a new class as public methods (this is what I read on SO mainly, I think this is a good habit).
The Boost unit test works with a system of fixture. A fixture is a context in which the tests will be executed. You can add public attributes to the fixture, such as
and
myArraySizewill be available as-is in the test cases code, as if you were writing the code of a method of the fixture. Usually the fixture has at least one attribute, an instance of the tested class.As well you can use the constructor of the fixture in order to do more complicated context initialization.
Boost give us some macro to perform various forms of checks, I listed some of these here:
BOOST_CHECK();BOOST_CHECK_EQUAL();BOOST_REQUIRE();BOOST_REQUIRE_EQUAL();BOOST_CHECKtests the expression, and if it is false, it logs it and then continues.BOOST_REQUIREtests the expression, and if this is false, it stops the current test case. This is used when the following code have no sense if the expression is false.*_EQUALshould be used to check equality between two expressions rather than using==because it display useful debug info on the values if the test fails. Note that this variant can be used only if both expressions can be printed withstd::cout(I don't think this is noted in the Boost doc, but I saw this when compiling my tests on another project).TODO:
TheoVerhelst included the following code: https://github.com/ulb-infof209/Group5/pull/35/commits