Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you implement unit-testing in large scale C++ projects? [closed]

I believe strongly in using unit-tests as part of building large multi-platform applications. We currently are planning on having our unit-tests within a separate project. This has the benefit of keeping our code base clean. I think, however, that this would separate the test code from the implementation of the unit. What do you think of this approach and are there any tools like JUnit for c++ applications?

like image 760
Charles Beattie Avatar asked Sep 18 '08 11:09

Charles Beattie


People also ask

What can be used for unit testing in C?

The most scalable way to write unit tests in C is using a unit testing framework, such as: CppUTest. Unity. Google Test.

What are the steps required to perform unit testing?

A unit test typically comprises of three stages: plan, cases and scripting and the unit test itself. In the first step, the unit test is prepared and reviewed. The next step is for the test cases and scripts to be made, then the code is tested.


2 Answers

There are many Test Unit frameforks for C++. CppUnit is certainly not the one I would choose (at least in its stable version 1.x, as it lacks many tests, and requires a lot of redundant lines of codes). So far, my preferred framework is CxxTest, and I plan on evaluating Fructose some day.

Any way, there are a few "papers" that evaluate C++ TU frameworks :

  • Exploring the C++ Unit Testing Framework Jungle, By Noel Llopis
  • an article in Overload Journal #78
like image 106
3 revs, 3 users 93% Avatar answered Sep 30 '22 07:09

3 revs, 3 users 93%


That's a reasonable approach.

I've had very good results both with UnitTest++ and Boost.Test

I've looked at CppUnit, but to me, it felt more like a translation of the JUnit stuff than something aimed at C++.

Update: These days I prefer using Catch. I found it to be effective and simple to use.

like image 23
Ferruccio Avatar answered Sep 30 '22 07:09

Ferruccio