Testing DLL with Boost :: Test?

I am developing a C ++ DLL and want to do unit testing of this DLL using Boost test libraries. I carefully read the Boost testing guide, but since I'm new, I have the following question:

Should I add test classes to the same VC project in which I am developing my DLL ?. Ideally, I want to do this, but I'm confused by the fact that the DLL does not have main() , and on the other hand, the Boost test requires its own main() to execute. So where is the Boost test result in this scenario? (In fact, I practically realized this and I see no way out: (and almost spent two days figuring out the problem, but not getting success)

Hello,

Jame.

+4
source share
2 answers

You have 3 ways to do this:

  • You can definitely do what the other answer offers, and create your library as static. I would not recommend this method, though.

  • Your solution may have one or more separate unit test projects. These projects will be linked to your library and to the static or general version of the Boost Test library. Each project will either have a main one, or supplied by the Boost.Test library, or implemented manually by you.

  • Finally, you have another option, and you can put your test cases directly into your library. You will need to install a link with the general version of the Boost test. Once your library is built, you can use it regularly, as it is now, plus you will have the opportunity to run test files built into it. To run a test case, you will need a test runner. The Boost Test offers one of these, called the "console test runner." You will need to create it once, and you can use it for all your projects. Using this test runner, you can run your unit test as follows:

    test_runner.exe --test "your_lib" .dll

    You must understand all the pros and cons of this approach. Your unit test code will be part of your production library. This will make it a little bigger, but on the other hand, you can run the test during production, if necessary.

+4
source

First you can create your DLL as a static library file. You can then use it to compile your latest DLL directly and create an executable file that contains your boost tests. Here is an example of using boost.build:

 lib lib_base : # sources $(MAIN_SOURCES).cpp # Sources for the library. : # requirements <link>static : : ; lib dll_final : # sources lib_base $(DLL_SOURCES).cpp # Sources for DllMain . : # requirements <link>shared : : ; unit-test test_exe : # sources lib_base $(TEST_SOURCES).cpp # Sources for the unit tests. : # properties <library>/site-config//boost/test ; 

You need to be careful not to have any important logic in DllMain , but usually a bad idea .

+2
source

Source: https://habr.com/ru/post/1338366/


All Articles