Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-56361

Add a way to automatically destroy objects created dynamically within a test function, even if that test fails

    XMLWordPrintable

    Details

    • Type: Suggestion
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 5.9.0 Alpha
    • Component/s: Testing: QuickTest
    • Labels:
      None
    • Commits:
      7aaebe557476c088d339f1b4b114a671885c4ea8

      Description

      Dynamically created objects in tests should be destroyed. If they're not destroyed, they can interfere with future tests and make debugging difficult (extra items laying around can produce extra, unrelated debug output, for example).

      Manually destroying objects at the end of a test function isn't guaranteed to work, because the test can fail, which skips the destroy() call completely.

      In Qt Quick Controls 2, we've started using a "cleanup item", which fills the TestCase and is created and destroyed automatically in init() and cleanup(), respectively. This is a nice solution to the problem of having to manually destroy objects. It could be added to TestCase in some form. For example:

      function createObject(component, properties)
      

      Any objects that should be automatically destroyed at the end of the test can be created with this function, and will be parented to the cleanup item.

      In addition, I think that wait()ing until the object is actually destroyed before exiting cleanup() is a good idea, as it guarantees that each test starts on a clean slate.

        Attachments

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

          Activity

            People

            Assignee:
            mitch_curtis Mitch Curtis
            Reporter:
            mitch_curtis Mitch Curtis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes