Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use boost::unit_test?

I'm trying to learn how to test programs so I tried Boost. I've started reading it and here I've met this line:

Now I can compile it and link with the unit test framework.
From where and how am I suppose to get unit test framework? And what it is?
I just do not know what to eat it with. Could someone please provide some steps how to use it or maybe point me to some other tutorials where even simplest things like unit test framework and how to link it with will be explained.
Thanks

like image 928
There is nothing we can do Avatar asked Nov 06 '22 09:11

There is nothing we can do


1 Answers

Just a fast comment. The problem with this library is that it has at least three different ways of implementing and running the tests. Depending on what #defines you add to your code before including the boost unit test header, it can automatically generate a main function for you (and then build a complete program that executes the tests you've defined), or rely on external test runners.

Read carefully those running modes to know what to do. Usually, the easiest way is to do this:

  • Include your tests in a .cpp file.
  • Before including the unit test header file, define the preprocessor macro BOOST_TEST_MAIN (this will define a main function that will run the tests)
  • Link your program against the libboost-unit-test DLL (this is system dependant).

Your program will execute the tests defined, thank to the automatically generated main function.

like image 50
Diego Sevilla Avatar answered Nov 09 '22 11:11

Diego Sevilla