diff --git a/plugins/junit5_rt/src/com/intellij/junit5/JUnit5TestExecutionListener.java b/plugins/junit5_rt/src/com/intellij/junit5/JUnit5TestExecutionListener.java index 9ccc7f3237f3..44d75e8ba546 100644 --- a/plugins/junit5_rt/src/com/intellij/junit5/JUnit5TestExecutionListener.java +++ b/plugins/junit5_rt/src/com/intellij/junit5/JUnit5TestExecutionListener.java @@ -106,8 +106,8 @@ public class JUnit5TestExecutionListener implements TestExecutionListener { HashSet visited) { final String idAndName = idAndName(root); if (root.isContainer()) { - boolean isEngine = isEngine(root); - if (!isEngine) myPrintStream.println("##teamcity[suiteTreeStarted" + idAndName + " " + getLocationHint(root) + "]"); + boolean skipContainer = shouldSkipContainer(root); + if (!skipContainer) myPrintStream.println("##teamcity[suiteTreeStarted" + idAndName + " " + getLocationHint(root) + "]"); for (TestIdentifier childIdentifier : myTestPlan.getChildren(root)) { if (visited.add(childIdentifier)) { sendTreeUnderRoot(childIdentifier, visited); @@ -116,7 +116,7 @@ public class JUnit5TestExecutionListener implements TestExecutionListener { System.err.println("Identifier '" + getId(childIdentifier) + "' is reused"); } } - if (!isEngine) myPrintStream.println("##teamcity[suiteTreeEnded" + idAndName + "]"); + if (!skipContainer) myPrintStream.println("##teamcity[suiteTreeEnded" + idAndName + "]"); } else if (root.isTest()) { myPrintStream.println("##teamcity[suiteTreeNode " + idAndName + " " + getLocationHint(root) + "]"); @@ -139,7 +139,7 @@ public class JUnit5TestExecutionListener implements TestExecutionListener { testStarted(testIdentifier); myCurrentTestStart = System.currentTimeMillis(); } - else if (!isEngine(testIdentifier)) { + else if (!shouldSkipContainer(testIdentifier)) { myFinishCount = 0; myPrintStream.println("##teamcity[testSuiteStarted" + idAndName(testIdentifier) + getLocationHint(testIdentifier) + "]"); } @@ -169,7 +169,7 @@ public class JUnit5TestExecutionListener implements TestExecutionListener { testFinished(testIdentifier, duration); myFinishCount++; } - else if (!isEngine(testIdentifier)){ + else if (!shouldSkipContainer(testIdentifier)){ String messageName = null; if (status == TestExecutionResult.Status.FAILED) { messageName = MapSerializerUtil.TEST_FAILED; @@ -204,11 +204,13 @@ public class JUnit5TestExecutionListener implements TestExecutionListener { } } - private static boolean isEngine(TestIdentifier testIdentifier) { + private boolean shouldSkipContainer(TestIdentifier testIdentifier) { UniqueId id = UniqueId.parse(testIdentifier.getUniqueId()); List segments = id.getSegments(); if (segments.isEmpty()) return false; - return segments.get(segments.size() - 1).getType().equals("engine"); + UniqueId.Segment lastSegment = segments.get(segments.size() - 1); + return lastSegment.getType().equals("engine") || + myRootName != null && myRootName.equals(lastSegment.getValue()); } protected long getDuration() { @@ -319,7 +321,7 @@ public class JUnit5TestExecutionListener implements TestExecutionListener { Optional parent = myTestPlan.getParent(testIdentifier); return parent - .map(identifier -> isEngine(identifier) ? getParentId(identifier) : identifier.getUniqueId() + myIdSuffix) + .map(identifier -> shouldSkipContainer(identifier) ? getParentId(identifier) : identifier.getUniqueId() + myIdSuffix) .orElse("0"); } diff --git a/plugins/junit5_rt/src/com/intellij/junit5/JUnit5TestRunnerUtil.java b/plugins/junit5_rt/src/com/intellij/junit5/JUnit5TestRunnerUtil.java index 00b4c22a2115..cbc3ebe5fce9 100644 --- a/plugins/junit5_rt/src/com/intellij/junit5/JUnit5TestRunnerUtil.java +++ b/plugins/junit5_rt/src/com/intellij/junit5/JUnit5TestRunnerUtil.java @@ -3,10 +3,7 @@ package com.intellij.junit5; import org.junit.platform.commons.util.AnnotationUtils; import org.junit.platform.engine.DiscoverySelector; -import org.junit.platform.engine.discovery.ClassNameFilter; -import org.junit.platform.engine.discovery.ClasspathRootSelector; -import org.junit.platform.engine.discovery.DiscoverySelectors; -import org.junit.platform.engine.discovery.PackageNameFilter; +import org.junit.platform.engine.discovery.*; import org.junit.platform.launcher.LauncherDiscoveryRequest; import org.junit.platform.launcher.TagFilter; import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; @@ -69,7 +66,7 @@ public class JUnit5TestRunnerUtil { List selectors = new ArrayList<>(); while ((line = reader.readLine()) != null) { - DiscoverySelector selector = createSelector(line); + DiscoverySelector selector = createSelector(line, null); if (selector != null) { selectors.add(selector); } @@ -119,7 +116,7 @@ public class JUnit5TestRunnerUtil { builder = builder.configurationParameter("junit.jupiter.conditions.deactivate", disableDisabledCondition); } - DiscoverySelector selector = createSelector(suiteClassNames[0]); + DiscoverySelector selector = createSelector(suiteClassNames[0], packageNameRef); assert selector != null : "selector by class name is never null"; return builder.selectors(selector).build(); } @@ -205,7 +202,7 @@ public class JUnit5TestRunnerUtil { * Unique id is prepended with prefix: @see com.intellij.execution.junit.TestUniqueId#getUniqueIdPresentation() * Method contains ',' */ - protected static DiscoverySelector createSelector(String line) { + protected static DiscoverySelector createSelector(String line, String[] packageNameRef) { if (line.startsWith("\u001B")) { String uniqueId = line.substring("\u001B".length()); return DiscoverySelectors.selectUniqueId(uniqueId); @@ -220,9 +217,16 @@ public class JUnit5TestRunnerUtil { } } else if (line.contains(",")) { - return DiscoverySelectors.selectMethod(line.replaceFirst(",", "#")); + MethodSelector selector = DiscoverySelectors.selectMethod(line.replaceFirst(",", "#")); + if (packageNameRef != null) { + packageNameRef[0] = selector.getClassName(); + } + return selector; } else { + if (packageNameRef != null) { + packageNameRef[0] = line; + } return DiscoverySelectors.selectClass(line); } } diff --git a/plugins/junit5_rt_tests/test/com/intellij/junit5/JUnit5EventsTest.java b/plugins/junit5_rt_tests/test/com/intellij/junit5/JUnit5EventsTest.java index f5a5223e2bb0..ded9e1b7a9ba 100644 --- a/plugins/junit5_rt_tests/test/com/intellij/junit5/JUnit5EventsTest.java +++ b/plugins/junit5_rt_tests/test/com/intellij/junit5/JUnit5EventsTest.java @@ -89,7 +89,16 @@ public class JUnit5EventsTest { c.addChild(testDescriptor); TestIdentifier identifier = TestIdentifier.from(testDescriptor); final TestPlan testPlan = TestPlan.from(Collections.singleton(engineDescriptor), EMPTY_PARAMETER); + //run from class + myExecutionListener.setRootName("testClass"); + myExecutionListener.testPlanExecutionStarted(testPlan); + + //engine + myExecutionListener.executionStarted(TestIdentifier.from(engineDescriptor)); + //class + myExecutionListener.executionStarted(TestIdentifier.from(c)); + myExecutionListener.executionStarted(identifier); MultipleFailuresError multipleFailuresError = new MultipleFailuresError("2 errors", Arrays.asList (new AssertionFailedError("message1", "expected1", "actual1"), @@ -98,15 +107,19 @@ public class JUnit5EventsTest { myExecutionListener.reportingEntryPublished(identifier, reportEntry); myExecutionListener.executionFinished(identifier, TestExecutionResult.failed(multipleFailuresError)); + myExecutionListener.executionFinished(TestIdentifier.from(c), TestExecutionResult.successful()); + myExecutionListener.executionFinished(TestIdentifier.from(engineDescriptor), TestExecutionResult.successful()); + String lineSeparators = StringUtil.convertLineSeparators(myBuf.toString()).replaceAll("|r", ""); Assertions.assertEquals("##teamcity[enteredTheMatrix]\n" + - "##teamcity[testStarted id='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' name='test1()' nodeId='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' parentNodeId='|[engine:engine|]/|[class:testClass|]' locationHint='java:test://com.intellij.junit5.JUnit5EventsTest$TestClass/test1' metainfo='']\n" + - "##teamcity[testStdOut id='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' name='test1()' nodeId='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' parentNodeId='|[engine:engine|]/|[class:testClass|]' out = 'timestamp = " + reportEntry.getTimestamp() + ", key1 = value1, stdout = out1|n']\n" + - "##teamcity[testFailed name='test1()' id='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' nodeId='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' parentNodeId='|[engine:engine|]/|[class:testClass|]' message='message1|nComparison Failure: ' expected='expected1' actual='actual1' details='']\n" + - "##teamcity[testFailed name='test1()' id='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' nodeId='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' parentNodeId='|[engine:engine|]/|[class:testClass|]' message='message2|nComparison Failure: ' expected='expected2' actual='actual2' details='']\n" + - "##teamcity[testFailed name='test1()' id='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' nodeId='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' parentNodeId='|[engine:engine|]/|[class:testClass|]' message='2 errors (2 failures)|n\torg.opentest4j.AssertionFailedError: message1|n\torg.opentest4j.AssertionFailedError: message2' details='TRACE']\n" + - "##teamcity[testFinished id='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' name='test1()' nodeId='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' parentNodeId='|[engine:engine|]/|[class:testClass|]']\n", + "##teamcity[rootName name = 'testClass' location = 'java:suite://testClass']\n" + + "##teamcity[testStarted id='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' name='test1()' nodeId='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' parentNodeId='0' locationHint='java:test://com.intellij.junit5.JUnit5EventsTest$TestClass/test1' metainfo='']\n" + + "##teamcity[testStdOut id='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' name='test1()' nodeId='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' parentNodeId='0' out = 'timestamp = " + reportEntry.getTimestamp() +", key1 = value1, stdout = out1|n']\n" + + "##teamcity[testFailed name='test1()' id='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' nodeId='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' parentNodeId='0' message='message1|nComparison Failure: ' expected='expected1' actual='actual1' details='']\n" + + "##teamcity[testFailed name='test1()' id='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' nodeId='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' parentNodeId='0' message='message2|nComparison Failure: ' expected='expected2' actual='actual2' details='']\n" + + "##teamcity[testFailed name='test1()' id='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' nodeId='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' parentNodeId='0' message='2 errors (2 failures)|n\torg.opentest4j.AssertionFailedError: message1|n\torg.opentest4j.AssertionFailedError: message2' details='TRACE']\n" + + "##teamcity[testFinished id='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' name='test1()' nodeId='|[engine:engine|]/|[class:testClass|]/|[method:testMethod|]' parentNodeId='0']\n", lineSeparators); }