@@ -462,7 +462,7 @@ public void updateTestSuiteCountersAndResult(IContext context, TestSuite testSui
462462 long pendingCount = getTestSuiteCount (context , testSuite , "[Result = '_1_Running' or Result = empty]" );
463463
464464 testSuite .setTestCount (testCount );
465- LOG .trace ("Updated test count to " + succeededCount );
465+ LOG .trace ("Updated test count to " + testCount );
466466
467467 testSuite .setTestPassedCount (succeededCount );
468468 LOG .trace ("Updated test suite succeeded count to " + succeededCount );
@@ -549,6 +549,11 @@ public synchronized void findAllTests(IContext context) throws CoreException {
549549 updateUnitTestList (context , testSuite );
550550 }
551551
552+ /*
553+ * Remove unit tests from orphaned modules
554+ */
555+ deleteUnitTestsFromOrphanedModules (context , modules );
556+
552557 /*
553558 * Remove all modules without tests
554559 */
@@ -585,7 +590,7 @@ private synchronized TestSuite findOrCreateTestSuite(IContext context, String mo
585590 }
586591 }
587592
588- private synchronized void deleteTestSuitesWithoutTest (IContext context ) throws CoreException {
593+ private synchronized void deleteTestSuitesWithoutTest (IContext context ) {
589594 StringBuilder query = new StringBuilder ();
590595 query .append (String .format ("//%s" , TestSuite .entityName ));
591596 query .append ("[not(" + UnitTest .MemberNames .UnitTest_TestSuite + "/" + UnitTest .entityName + ")]" );
@@ -594,6 +599,27 @@ private synchronized void deleteTestSuitesWithoutTest(IContext context) throws C
594599 Core .delete (context , testSuites );
595600 }
596601
602+ private synchronized void deleteUnitTestsFromOrphanedModules (IContext context , Set <String > currentModules ) {
603+ List <IMendixObject > allTestSuites = Core .createXPathQuery ("//" + TestSuite .entityName ).execute (context );
604+
605+ for (IMendixObject mxObject : allTestSuites ) {
606+ TestSuite testSuite = TestSuite .initialize (context , mxObject );
607+
608+ if (!currentModules .contains (testSuite .getModule ())) {
609+ StringBuilder query = new StringBuilder ();
610+ query .append (String .format ("//%s" , UnitTest .entityName ));
611+ query .append (String .format ("[%s=$TestSuite]" , UnitTest .MemberNames .UnitTest_TestSuite ));
612+
613+ List <IMendixObject > orphanedUnitTests = Core .createXPathQuery (query .toString ())
614+ .setVariable ("TestSuite" , testSuite .getMendixObject ().getId ().toLong ()).execute (context );
615+
616+ if (!orphanedUnitTests .isEmpty ()) {
617+ Core .delete (context , orphanedUnitTests );
618+ }
619+ }
620+ }
621+ }
622+
597623 public synchronized void updateUnitTestList (IContext context , TestSuite testSuite ) {
598624 try {
599625 /*
0 commit comments