Test units, assertions and return code


#1

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?

Thanks,
Julien.


#2

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

ConsoleUnitTestRunner runner;
runner.runAllTests();

// 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.


#3

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


#4

You should use the methods of the UnitTest class:

expect
expectEquals
expectGreaterThan
...

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.


#5

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.

Thanks!