Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a Makefile.am to invoke googletest unit tests

I am trying to add my first unit test to an existing Open Source project. Specifically, I added a new class, called audio_manager:

src/audio/audio_manager.h
src/audio/audio_manager.cc

I created a src/test directory structure that mirrors the structure of the implementation files, and wrote my googletest unit tests:

src/test/audio/audio_manager.cc

Now, I am trying to set up my Makefile.am to compile and run the unit test:

src/test/audio/Makefile.am

I copied Makefile.am from:

src/audio/Makefile.am

Does anyone have a simple recipe for me, or is it to the cryptic automake documentation for me? :)

like image 313
Josh Glover Avatar asked Mar 17 '10 11:03

Josh Glover


1 Answers

If the existing project already has a test structure in place, then you should just add:

TESTS += audio_manager

to the existing tests/Makefile.am. If the existing project does not have a test structure in place, you should run screaming for the hills.

If running for the hills is not acceptable, there's a fair bit of work in getting the test structure in place, but it's not insurmountable. You might prefer to make tests a sibling of src, but that's not necessary. It's probably easier to start with a fresh Makefile.am rather than copying the Makefile.am from src, but maybe not. Possibly, all you'll need to do is change lines of the form:

bin_PROGRAMS = ...

to

check_PROGRAMS = ...

add the line

TESTS = test-audio-manager

change the name of audio_manager.cc to test-audio-manager.cc (that's not strictly necessary, but will help maintainability. I changed _ to - purely out of personal preference) and add a

SUBDIRS = tests/audio

to src/Makefile.am. (If there's already a SUBDIRS directive, append to that assignment or use +=)

like image 92
William Pursell Avatar answered Oct 10 '22 06:10

William Pursell