Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Add Unity c unit test framework to QtCreator
Forum Updated to NodeBB v4.3 + New Features

Add Unity c unit test framework to QtCreator

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
3 Posts 2 Posters 539 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kDohmen
    wrote on 13 Jul 2019, 10:56 last edited by
    #1

    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?

    A 1 Reply Last reply 13 Jul 2019, 11:54
    0
    • K kDohmen
      13 Jul 2019, 10:56

      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?

      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 13 Jul 2019, 11:54 last edited by
      #2

      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:

      https://codereview.qt-project.org/c/qt-creator/qt-creator/+/152099
      https://codereview.qt-project.org/c/qt-creator/qt-creator/+/261243

      Maybe one of them gives you some more insight.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      2
      • A Offline
        A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on 15 Jul 2019, 07:38 last edited by
        #3

        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)
        {
            UNITY_PRINT_EOL();
            UnityPrint("file://");
            UnityPrint(file);
            UNITY_OUTPUT_CHAR(':');
            UnityPrintNumber((UNITY_INT)line);
            UNITY_OUTPUT_CHAR(':');
            UnityPrint(Unity.CurrentTestName);
            UNITY_OUTPUT_CHAR(':');
        }
        

        Regards

        Qt has to stay free or it will die.

        1 Reply Last reply
        2

        1/3

        13 Jul 2019, 10:56

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved