Modern testing on the C ++ module?

What are the most modern unit testing approaches for C ++? A class of languages โ€‹โ€‹with a greater ability for introspection (for example, Python) has unit testing modules that are more natural to use. Unit tests can be defined more easily. In comparison, the classic CppUnit (based on JUnit ) seems to take a very conservative approach. Is there something new and better that uses a certain power of C ++ (or even C ++ 11) to make life easier?

I used the CppUnit for some time quite simplified for parts of the project in my native C ++ Windows (Visual Studio 2005 and 2010). Previously, we did not choose a testing-based approach, because there was already a lot of outdated code, and it was difficult for us to add tests for it. We had to reorganize the application, but adding all the good tests would take a lot of time even in this case.

We recently switched to Visual Studio 2013 (due to the standard implementation of C ++ 11), and we are going to start a new, rather long-term project.

Having previous good (small) experience with unit testing, I would like to try the Test Driven Development approach. Since the project is not tiny (the expected size is about the same as the older one, i.e. about 200 thousand lines of code), I prefer a lighter (but no less workable) structure.

The new project is likely to lead to cross-platform implementation (Windows and Linux). Visual Studio 2013 has support for unit testing, but I have no experience working with it and how it will fit the cross-platform platform.

So far I have found a list of unit testing modules for C ++ . However, it is impossible to understand how they differ in principle. I currently have three candidates (conservative choice):

  • Boost - a likely candidate; test for C ++ standards; therefore, it is likely that it will be widely accepted; probably the largest user group. It seems to be more advanced than CppUnit .
  • CppUnit - I know this, but writing all the code around is not a pleasure.
  • Visual Studio 2013 is built-in - new to me, somehow it can generate skeletons, probably.

In any case, it seems that all three take a similar approach. VS2013 may support code generation, but this does not mean that it leads to anything simpler.

Is there a radically new approach?

+47
c ++ cross-platform unit-testing visual-studio visual-studio-2013
Dec 16 '13 at 8:58
source share
2 answers

The only test framework worth considering: Catch

For an introduction to lib see also here and here

It is easy to use (only for the header, consisting of only one header), portable and, of course, the simplest and cleanest syntax of any C ++ module testing platform.

And unlike other libraries, you do not need to remember two dozen different macros f or different types of statements.

You just use REQUIRE:

 int one = 1; REQUIRE( one == 2 ); 

which, through some clever operator overloading, will show both the original expression and the extended values โ€‹โ€‹of the argument in the output:

 test.cc(7): FAILED: REQUIRE( one == 2 ) with expansion: 1 == 43 

Compared to this, any other structure is the difficulty of using IMO.

I used to use this Boost.Test test, but it was a lot harder to set up and use. We use CppUnit at work, and this, apparently, should be as fragile and painful as possible.

I looked briefly at the VS2013 test environment, but I havenโ€™t tried it, and it looks tolerable, but very similar to emulating the "old guard". In fact, it does not try to be cleaner, simpler or better than CppUnit, Boost.Test and all the others that appeared before Catch. So I would say donโ€™t worry. Tests should be easy to write (and understand), and Catch should be lighter than all the other frameworks I've seen on this front.

+49
Dec 16 '13 at
source share

I use Visual Studio 2013, which is built into the test environment, for about 6 weeks and I really like it. The integration is great and very easy to pick up. If you are working on a project that is designed for Windows only, then I recommend it.

+4
Dec 16 '13 at 9:39 on
source share



All Articles