<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QTest how to cleanly handle 2 QCoreApplications? the one for QTest::qExec and the one of my app I&#x27;m testing ? Except leaking....]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I'm having a big trouble to handle properly 2 QCoreApplication.<br />
I launch the test with its own event loop.<br />
For some test case, when needed, I start the one of my App, I can also quit it.<br />
But I'm having a massive crash if I try to delete my app, so I need to keep a memory leak...<br />
That's not a big deal, but it's not ideal.<br />
I'd like to undestand how to do it properly.<br />
Anyone has some experience with that?<br />
My project is ngPost. The branch dev5.0 starts implementing tests.<br />
If anyone has time or an idea, I'll be super happy !<br />
My structure is this: a <a href="https://github.com/mbruel/ngPost/blob/dev_v5.0/src/test_ngPost.pro" target="_blank" rel="noopener noreferrer nofollow ugc">test_ngPost.pro</a>  that defines a <a href="https://github.com/mbruel/ngPost/blob/dev_v5.0/src/tests/MacroTest.h" target="_blank" rel="noopener noreferrer nofollow ugc">Macro helper</a> and 2 test cases. ( TestNzbGet is not started and all commented.)<br />
Basically my Macro allows me to have global statistiques at the end: number of Tests that fails with their number of unitests, I didnt know how to do it in another way. The import thing is that the test ends with exit value the number of all the unit cases that failed.. Usefull for jenkins ;)<br />
Is there a Qt way?<br />
Here are my results:</p>
<pre><code>Configuration version needs update!
QDEBUG : TestNgTools::onCheckForNewVesion() [MB_LOG] ../src/tests/testNgTools.cpp:127 TestNgTools::onCheckForNewVersionReply: lastRelease:  
QDEBUG : TestNgTools::onCheckForNewVesion() [MB_LOG] ../src/tests/testNgTools.cpp:127 416 
QDEBUG : TestNgTools::onCheckForNewVesion() [MB_LOG] ../src/tests/testNgTools.cpp:127 currentBuilt: 
QDEBUG : TestNgTools::onCheckForNewVesion() [MB_LOG] ../src/tests/testNgTools.cpp:127 400 
QDEBUG : TestNgTools::onCheckForNewVesion() Deleting ngPost...
PASS   : TestNgTools::onCheckForNewVesion()
QWARN  : TestNgTools::onCheckForNewVersionReply() qt.core.qobject.connect: QObject::disconnect: Unexpected nullptr parameter
QDEBUG : TestNgTools::onCheckForNewVersionReply() Deleting ngPost...
PASS   : TestNgTools::onCheckForNewVersionReply()
QDEBUG : TestNgTools::cleanupTestCase() Destruction of the singleton NgLogger
PASS   : TestNgTools::cleanupTestCase()
Totals: 7 passed, 0 failed, 0 skipped, 0 blacklisted, 157ms
********* Finished testing of TestNgTools *********
[ TestNgTools ] QTest::qExec return:  0





###############################################
# Results Macro Test:  "TestNgTools"
#     - number of use cases:  27
#     - number of checks:  0
#     - number of Failures:  0
###############################################
********* Start testing of TestVesions *********
Config: Using QtTest library 6.4.0, Qt 6.4.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 10.3.1 20210422 (Red Hat 10.3.1-1)), debian 12
QDEBUG : TestVesions::initTestCase() Creation of the singleton NgLogger
PASS   : TestVesions::initTestCase()
QDEBUG : TestVesions::onTestLoadDefautConfig() onTestLoadDefautConfig...
QDEBUG : TestVesions::onTestLoadDefautConfig() Config version :  "3.2"
QDEBUG : TestVesions::onTestLoadDefautConfig() [MB_TODO] why pushing args.join("=") ??  QList("echo \"NZB_POST_CMD echo: &lt;release: __nzbName__&gt; &lt;rarName: __rarName__&gt; &lt;rarPass: __rarPass__&gt; &lt;path: __nzbPath__&gt; &lt;groups: __groups__&gt; &lt;size: __sizeInByte__B&gt; &lt;nbFiles: __nbFiles__&gt; &lt;nbArticles: __nbArticles__&gt; &lt;failed: __nbArticlesFailed__&gt;\"", "echo \"NZB_POST_CMD echo: &lt;release: __nzbName__&gt; &lt;rarName: __rarName__&gt; &lt;rarPass: __rarPass__&gt; &lt;path: __nzbPath__&gt; &lt;groups: __groups__&gt; &lt;size: __sizeInByte__B&gt; &lt;nbFiles: __nbFiles__&gt; &lt;nbArticles: __nbArticles__&gt; &lt;failed: __nbArticlesFailed__&gt;\"", "echo \"NZB_POST_CMD echo: &lt;release: __nzbName__&gt; &lt;rarName: __rarName__&gt; &lt;rarPass: __rarPass__&gt; &lt;path: __nzbPath__&gt; &lt;groups: __groups__&gt; &lt;size: __sizeInByte__B&gt; &lt;nbFiles: __nbFiles__&gt; &lt;nbArticles: __nbArticles__&gt; &lt;failed: __nbArticlesFailed__&gt;\"")
QDEBUG : TestVesions::onTestLoadDefautConfig() Display progressbar bar

QDEBUG : TestVesions::onTestLoadDefautConfig() Leaking ngPost...
PASS   : TestVesions::onTestLoadDefautConfig()
QDEBUG : TestVesions::onTestLoadOldConfig() onTestLoadOldConfig...
QDEBUG : TestVesions::onTestLoadOldConfig() Leaking ngPost...
PASS   : TestVesions::onTestLoadOldConfig()
QDEBUG : TestVesions::cleanupTestCase() Destruction of the singleton NgLogger
PASS   : TestVesions::cleanupTestCase()
Totals: 4 passed, 0 failed, 0 skipped, 0 blacklisted, 4ms
********* Finished testing of TestVesions *********
[ TestVesions ] QTest::qExec return:  0





###############################################
# Results Macro Test:  "TestVesions"
#     - number of use cases:  0
#     - number of checks:  0
#     - number of Failures:  0
###############################################





###############################################
# Overall Tests Results:
#     - number of Macro Tests:  2
#     - number of Macro Tests FAILED:  0
#

#     - number of Unit Tests:  27
#     - number of Unit Tests FAILED:  0
###############################################
22:38:04: /home/mb/Documents/github/ngPost/build-test_ngPost-Desktop_Qt_6_4_0_GCC_64bit-Debug/ngPost exited with code 0

</code></pre>
<p dir="auto">So we can see the tests are lanched independantly and using their own instance of my App. Leaking it allows me to get the result I want but I'm not a fan of this and would like to understant how to do better,<br />
If anyone can help, it would be welcome ;)</p>
]]></description><link>https://forum.qt.io/topic/156942/qtest-how-to-cleanly-handle-2-qcoreapplications-the-one-for-qtest-qexec-and-the-one-of-my-app-i-m-testing-except-leaking</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Apr 2026 02:57:22 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/156942.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 29 May 2024 20:47:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QTest how to cleanly handle 2 QCoreApplications? the one for QTest::qExec and the one of my app I&#x27;m testing ? Except leaking.... on Sat, 01 Jun 2024 16:07:18 GMT]]></title><description><![CDATA[<p dir="auto">I found the solution using QTest::qWaitFor cf my project <a href="https://github.com/mbruel/ngPost/blob/dev_v5.0/src/tests/LoadConfig/TestVesions.cpp#L40" target="_blank" rel="noopener noreferrer nofollow ugc">TestVesions</a></p>
<pre><code>    ConnectionHandler *conHandler = TestUtils::loadXSNewsPartnerConfAndCheckConnection(*_ngPost);
    conHandler-&gt;start();
    MB_VERIFY(QTest::qWaitFor([&amp;conHandler]() { return conHandler-&gt;isTestDone(); }, 5000), this);
</code></pre>
]]></description><link>https://forum.qt.io/post/801517</link><guid isPermaLink="true">https://forum.qt.io/post/801517</guid><dc:creator><![CDATA[mbruel]]></dc:creator><pubDate>Sat, 01 Jun 2024 16:07:18 GMT</pubDate></item><item><title><![CDATA[Reply to QTest how to cleanly handle 2 QCoreApplications? the one for QTest::qExec and the one of my app I&#x27;m testing ? Except leaking.... on Thu, 30 May 2024 17:31:48 GMT]]></title><description><![CDATA[<p dir="auto">Yes I know but I would also like to do Macro testing...<br />
Something I'm not understanding, the test.main() doesn't seem to wait for a QThread started to be waited... Is it normal?</p>
]]></description><link>https://forum.qt.io/post/801294</link><guid isPermaLink="true">https://forum.qt.io/post/801294</guid><dc:creator><![CDATA[mbruel]]></dc:creator><pubDate>Thu, 30 May 2024 17:31:48 GMT</pubDate></item><item><title><![CDATA[Reply to QTest how to cleanly handle 2 QCoreApplications? the one for QTest::qExec and the one of my app I&#x27;m testing ? Except leaking.... on Wed, 29 May 2024 21:57:39 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">From the <a href="https://doc.qt.io/qt-6/qcoreapplication.html#details" target="_blank" rel="noopener noreferrer nofollow ugc">QCoreApplication</a> docs, "For non-GUI application that uses Qt, there should be exactly one QCoreApplication object."</p>
<p dir="auto">It's not clear top me what this means, "For some test case, when needed, I start the one of my App, I can also quit it.  But I'm having a massive crash if I try to delete my app, so I need to keep a memory leak..."</p>
<p dir="auto">You should be unit testing individual components, not an entire running application.</p>
]]></description><link>https://forum.qt.io/post/801230</link><guid isPermaLink="true">https://forum.qt.io/post/801230</guid><dc:creator><![CDATA[ChrisW67]]></dc:creator><pubDate>Wed, 29 May 2024 21:57:39 GMT</pubDate></item></channel></rss>