Search code examples
unit-testinglanguage-agnosticautomated-testsautotools

How do you create tests for "make check" with GNU autotools


I'm using GNU autotools for the build system on a particular project. I want to start writing automated tests for verifcation. I would like to just type "make check" to have it automatically run these. My project is in C++, although I am still curious about writing automated tests for other languages as well.

Is this compatible with pretty much every unit testing framework out there (I was thinking of using cppunit)? How do I hook these unit testing frameworks into make check? Can I make sure that I don't require the unit test software to be installed to be able to configure and build the rest of the project?


Solution

  • To make test run when you issue make check, you need to add them to the TESTS variable

    Assuming you've already built the executable that runs the unit tests, you just add the name of the executable to the TESTS variable like this:

    TESTS=my-test-executable
    

    It should then be automatically run when you make check, and if the executable returns a non-zero value, it will report that as a test failure. If you have multiple unit test executables, just list them all in the TESTS variable:

    TESTS=my-first-test my-second-test my-third-test
    

    and they will all get run.