How to organize the tests

2,016 views
Skip to first unread message

Avihay Eyal

unread,
Aug 18, 2011, 9:44:43 AM8/18/11
to Google C++ Testing Framework
HI, I have a bunch of test, something like 4-5 groups of them.

What's the correct way to organize these tests? Should I put each
group in a single header and include all of them to a single cpp
calling the RUN_ALL_TEST function? Should I put them all in a single
file?

Thanks.

Mike Long

unread,
Aug 20, 2011, 2:18:09 PM8/20/11
to Avihay Eyal, Google C++ Testing Framework
Hi,

Yes, I put each test suite in its own cpp file, I don't put any test code in header files.  You can look at some of my github repos for examples:


Good luck!

./mike

On Thu, Aug 18, 2011 at 8:46 PM, Avihay Eyal <aviha...@gmail.com> wrote:
Hi, first of all thanks for the reply. What I've done is to put each of them in a separate header, and then I include them in a cpp file that's calling run_all_test. From what you wrote, I understand that each test suite is in it's own class?

Sent from my iPad

On 18 באוג 2011, at 18:06, Mike Long <mikelo...@gmail.com> wrote:

I usually put each group in a cpp file and link them together.  If you don't need to do anything special to start the tests I would just link in the gtest_main library so you don't need to bother with the RUN_ALL_TEST call.

Hope that helps,
Mike

Ken Turkowski

unread,
Aug 31, 2011, 9:03:32 PM8/31/11
to Avihay Eyal, Google C++ Testing Framework
I organize the tests modularly during test-driven development. I.e. when I undertake the development of a new technology, I write a test file exclusively for those related technologies.

Some of the test files are several thousands of lines each, with maybe 35 tests in each one. The intent is to fully exercise the module.

To run all of the tests, I use use a script containing something typically like this:
for file in *Test
do
./$file --verbose --write_images
done
I will usually run these before checking in a change, though occasionally I will do it afterward and very quickly submit a bug fix. ;-)

So I recommend that you have your tests grouped into 4 or 5 files.

-Ken

Reply all
Reply to author
Forward
0 new messages