Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-20746

Replacing QUICK_TEST_MAIN macro may cause Qt Quick test to disappear

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • Qt Creator 4.7.0
    • Qt Creator 4.6.2, Qt Creator 4.7.0-rc1
    • Test Integration
    • None
    • Windows 10.
    • Windows
    • 3a4592609c510dd18041cf3635d4c14477c585a6 f80aa2c6f7b85de4bbe050fb96bd6852908f3e58

    Description

      I want to register a C++ for use in a unit test. I succeeded, but the unit test disappears inconsistently in Qt Creator 4.6.2. When I determined how to reproduce this I tested on QC 4.7.0-rc1 and verified the same behavior.

      To register my C++ class, I expand the QUICK_TEST_MAIN macro in place and add the qmlRegisterType call. When I do this, the respective Qt Quick test becomes flaky and will disappear from the Tests view. The QUICK_TEST_MAIN macro seems to be key for showing Qt Quick tests in the Tests view, which I cannot find documented.

      Here are my steps to reproduce:

      1. To make this easier, split the "Projects" view and show the "Tests" view so that both are accessible.
      2. Create a "Other Project" | "Subdirs Project", name it "Tests", select a kit, press Next, then Finish & Add Subproject.
      3. Create a "Other Project" | "Auto Test Project", press Choose, name it "Test1", press Next, select the Qt Quick Test framework, name the Test case "Test1", select a kit, press Next, then Finish.
      4. Observe that there is a "Test1" Quick Test in the Tests view.
      5. In the "Projects" view, right-click the "Tests" project and select "New Subproject..."
      6. Create a "Other Project" | "Auto Test Project", press Choose, name it "Test2", press Next, select the Qt Quick Test framework, name the test case "Test2", select a kit, press Next, then Finish.
      7. Observe that there is now a "Test2" Quick Test in the Tests view.
      8. Open main.cpp in the "Test1" project for editing.
      9. Right-click the QUICK_TEST_MAIN macro name in the 3rd line and select the "Follow Symbol Under Cursor" menu option to jump to the declaration of the macro.
      10. Copy the selected macro definition (it's the first of the four similar macros) from the "int main ..." line to the closing brace and paste it into the main.cpp file just under the existing QUICK_TEST_MAIN macro.
      11. Comment out line 3 with the QUICK_TEST_MAIN macro.
      12. Replace the #name argument to quick_test_main() on line 9 with "test1" and save.
      13. Right-click the "Tests" view and choose "Rescan Tests".
      14. Observe that both Quick Tests are still available in the "Tests" view.
      15. Edit Tests.pro and comment out the subdir entry for Test2 and save. Wait a couple seconds while Qt Creator parses the .pro file changes.
      16. Observe that there are no Quick Tests anymore – they are both gone.
      17. Edit Test1/main.cpp and un-comment the 3rd line with the QUICK_TEST_MAIN macro.
        Observe that the Test1 Quick Test almost immediately appears, even without saving.
      18. Comment-out the 3rd line with the QUICK_TEST_MAIN macro again and save.
      19. Right-click the "Tests" view and choose "Rescan Tests".
      20. Observe that "Test1" is removed again.

      I attached my project at step 10 right before expanding the QUICK_TEST_MAIN macro in place. I did not insert code to register a C++ class for QML, but it would go inside main().

      The behavior is so consistent that I wonder if QUICK_TEST_MAIN is required for "Tests" view support. If it is, how can C++ classes be registered for use in QML while allowing the auto test to be accessible in the "Tests" View?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            cstenger Christian Stenger
            stan.m Stanley Morris
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes