Qt World Summit: Register Today!

Add Unity c unit test framework to QtCreator

  • Hello Qt Community,

    I wanted to add a new autotest framework to the Qt Creator autotest plugin.
    The framework is unity. It is very small and easy to use. And actively developed.
    While trying to add the new framework I just copied the code of gtest and wanted to alter it.
    In the *Visitor class the functions defining the test names should be extracted. But unity die not use function declarations or
    definitions to define a test. Test functions have to be called manually with the macro RUN_TEST(). So which
    CPlusPlus::*AST class is the best for extracting the function names from the RUN_TEST() macro? Maybe CPlusPlus::CallAST? Then how to get the callled function name from this *AST object?

  • Lifetime Qt Champion

    Hi @kDohmen,

    interesting, I'm using Unity since 6 years in Creator. I did not care much that it is not integrated in the AutoTest plugin. I modified Unity's output routine, so it prints "file://path/to/failed/file:linenumber" and voila: the link can be clicked in the Application Output and brings you to the failure.

    If, however, we have a full integration: that would be awesome!

    I cannot help you here, I have no knowlegde on the code model side, and I assume that applies to most others here too. You can probably ask on the mailing list to get an answer from the developers with deeper understanding.

    I'm also aware of two further auto test additons that are not merged yet:


    Maybe one of them gives you some more insight.


  • Lifetime Qt Champion

    Just as follow-up, these are the changes I made to integrate Unity in Creator:

    For the colored PASS/FAIL output, #define UNITY_OUTPUT_COLOR (e.g. in the .pro file), and change the color definitions to better fit the Application Output:

    static const char UnityStrOk[]     = "\033[32mOK\033[00m";
    static const char UnityStrPass[]   = "\033[32mPASS\033[00m";
    static const char UnityStrFail[]   = "\033[31mFAIL\033[00m";
    static const char UnityStrIgnore[] = "\033[33mIGNORE\033[00m";

    Add file:// before a test failure, that makes the file clickable in Application Output and brings you to the source code:

    static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)


Log in to reply