4

I am writing unit tests for a library written in Qt/C++.

The library is rather big, with lots of functionalities. I have a separate unitTest folder which I have my UnitTest.cpp in there. Having all test case / unit tests in the same file, makes it one very big .cpp file.

I was wondering what is the best approach to unit test huge libraries. Should I have different UnitTest.cpp files in different folder? Like one for every class? or every name space?

gnat
20.5k29 gold badges117 silver badges308 bronze badges
asked Jan 9, 2013 at 11:30

1 Answer 1

7

As you already discovered, putting all unit tests into one huge file is not a good practice (same as putting all classes into one file is bad as well, although it compiles a bit faster).

You should create a subdirectory unittests where all unit tests go. It should be one file per class. This way you do not clutter your code with unit tests.

If you can, split your big library into several small libraries (each in it's own directory). Each should have it's own namespace, and directory structure (main directory where the code is, and two subdirectories: one for unit tests, and other for mock classes).

answered Jan 9, 2013 at 12:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.