Test units, assertions and return code

I am currently building my project via Jenkins, it works fine. Now I would like to run all my unit tests, using a specific project. It also runs fine. However, failing tests are not detected: the failing assertions are not returning any “error code” to the main.cpp, and so it is not possible to easily check whether everything went fine or not.

Basically, I’d like a failing assert to be “automagically” detected by the caller of my .exe file (a .bat file could test “if ERRORLEVEL…”).

Has anyone found a convenient way to do so?


If you look at the JUCE UnitTestRunner project in extras, and modify the last bit of main.cpp to look like this

ConsoleUnitTestRunner runner;

// Add this...
for (int i = 0; i < runner.getNumResults(); ++i)
    if (runner.getResult (i)->failures > 0)
        return 1;

return 0;

then it’ll do what you want.

Thanks for your reply. However, I already tried that, and it doesn’t work. Assertion (like jassertfalse) are not considered as “failure” somehow…

You should use the methods of the UnitTest class:


These are what define the things you are actually testing. Assertions serve a slight different purpose, though by default test failures throw assertions too to make it easy way to get a debugger involved.

Had more time to test. You are right, it’s working well by using expect instead of jassert, indeed. It can then test the result via a simple bat file.