Details
-
Suggestion
-
Resolution: Done
-
P2: Important
-
None
-
None
-
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.