diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a337ba..4dcc07e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [10.0.4] - 2025-08-14 + +### Added: +- We fixed an issue where renaming or deleting a module resulted in the test suite overview showing incorrect data. + ## [10.0.3] - 2025-08-07 ### Added: diff --git a/dist/UnitTesting_10.0.4.mpk b/dist/UnitTesting_10.0.4.mpk new file mode 100644 index 0000000..f9d1160 Binary files /dev/null and b/dist/UnitTesting_10.0.4.mpk differ diff --git a/src/UnitTesting.mpr b/src/UnitTesting.mpr index 002f981..2c58734 100644 Binary files a/src/UnitTesting.mpr and b/src/UnitTesting.mpr differ diff --git a/src/javasource/unittesting/TestManager.java b/src/javasource/unittesting/TestManager.java index 70e3b96..0da9eae 100644 --- a/src/javasource/unittesting/TestManager.java +++ b/src/javasource/unittesting/TestManager.java @@ -462,7 +462,7 @@ public void updateTestSuiteCountersAndResult(IContext context, TestSuite testSui long pendingCount = getTestSuiteCount(context, testSuite, "[Result = '_1_Running' or Result = empty]"); testSuite.setTestCount(testCount); - LOG.trace("Updated test count to " + succeededCount); + LOG.trace("Updated test count to " + testCount); testSuite.setTestPassedCount(succeededCount); LOG.trace("Updated test suite succeeded count to " + succeededCount); @@ -549,6 +549,11 @@ public synchronized void findAllTests(IContext context) throws CoreException { updateUnitTestList(context, testSuite); } + /* + * Remove unit tests from orphaned modules + */ + deleteUnitTestsFromOrphanedModules(context, modules); + /* * Remove all modules without tests */ @@ -585,7 +590,7 @@ private synchronized TestSuite findOrCreateTestSuite(IContext context, String mo } } - private synchronized void deleteTestSuitesWithoutTest(IContext context) throws CoreException { + private synchronized void deleteTestSuitesWithoutTest(IContext context) { StringBuilder query = new StringBuilder(); query.append(String.format("//%s", TestSuite.entityName)); query.append("[not(" + UnitTest.MemberNames.UnitTest_TestSuite + "/" + UnitTest.entityName + ")]"); @@ -594,6 +599,27 @@ private synchronized void deleteTestSuitesWithoutTest(IContext context) throws C Core.delete(context, testSuites); } + private synchronized void deleteUnitTestsFromOrphanedModules(IContext context, Set currentModules) { + List allTestSuites = Core.createXPathQuery("//" + TestSuite.entityName).execute(context); + + for (IMendixObject mxObject : allTestSuites) { + TestSuite testSuite = TestSuite.initialize(context, mxObject); + + if (!currentModules.contains(testSuite.getModule())) { + StringBuilder query = new StringBuilder(); + query.append(String.format("//%s", UnitTest.entityName)); + query.append(String.format("[%s=$TestSuite]", UnitTest.MemberNames.UnitTest_TestSuite)); + + List orphanedUnitTests = Core.createXPathQuery(query.toString()) + .setVariable("TestSuite", testSuite.getMendixObject().getId().toLong()).execute(context); + + if (!orphanedUnitTests.isEmpty()) { + Core.delete(context, orphanedUnitTests); + } + } + } + } + public synchronized void updateUnitTestList(IContext context, TestSuite testSuite) { try { /*