How do you implement unit-testing in large scale C

2019-01-30 18:27发布

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?

9条回答
三岁会撩人
2楼-- · 2019-01-30 18:56

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.

查看更多
姐就是有狂的资本
3楼-- · 2019-01-30 18:56

I use UnitTest++. The tests are in a separate project but the actual tests are intertwined with the actual code. They exist in a folder under the section under test. ie:
MyProject\src\ <- source of the actual app
MyProject\src\tests <- the source of the tests
If you have nested folders (and who doesn't) then they too will have their own \tests subdirectory.

查看更多
走好不送
4楼-- · 2019-01-30 19:00

CxxTest is also worth a look for lightweight, easy to use cross platform JUnit/CppUnit/xUnit-like framework for C++. We find it very straightforward to add and develop tests

Aeryn is another C++ Testing Framework worth looking at

查看更多
登录 后发表回答