[junit 5] support for ignored containers (IDEA-204995)

GitOrigin-RevId: 0b7f9a023e204a45f0a0079552a869066f72ddee
This commit is contained in:
Anna Kozlova
2021-11-17 12:03:08 +00:00
committed by intellij-monorepo-bot
parent 89f876cca0
commit 940f19a861
2 changed files with 36 additions and 16 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.junit5;
import com.intellij.junit4.ExpectedPatterns;
@@ -200,6 +186,7 @@ public class JUnit5TestExecutionListener implements TestExecutionListener {
messageName = MapSerializerUtil.TEST_IGNORED;
}
if (messageName != null) {
final Set<TestIdentifier> descendants = myTestPlan != null ? myTestPlan.getDescendants(testIdentifier) : Collections.emptySet();
if (status == TestExecutionResult.Status.FAILED) {
String parentId = getParentId(testIdentifier);
String nameAndId = " name='" + CLASS_CONFIGURATION +
@@ -208,8 +195,10 @@ public class JUnit5TestExecutionListener implements TestExecutionListener {
testFailure(CLASS_CONFIGURATION, getId(testIdentifier), parentId, messageName, throwableOptional, 0, reason, true);
myPrintStream.println("##teamcity[testFinished" + nameAndId + "]");
}
else if (status == TestExecutionResult.Status.ABORTED && descendants.isEmpty()) {
testFailure(testIdentifier, MapSerializerUtil.TEST_IGNORED, throwableOptional, 0, reason, true);
}
final Set<TestIdentifier> descendants = myTestPlan != null ? myTestPlan.getDescendants(testIdentifier) : Collections.emptySet();
if (!descendants.isEmpty() && myFinishCount == 0) {
for (TestIdentifier childIdentifier : descendants) {
testStarted(childIdentifier);
@@ -141,6 +141,37 @@ public class JUnit5EventsTest {
"##teamcity[testFinished name='Class Configuration' nodeId='|[engine:testMethod|]' parentNodeId='|[engine:testClass|]' ]\n" +
"##teamcity[testSuiteFinished id='|[engine:testMethod|]' name='brokenStream()' nodeId='|[engine:testMethod|]' parentNodeId='|[engine:testClass|]']\n", StringUtil.convertLineSeparators(myBuf.toString()));
}
@Test
void containerDisabled() throws Exception {
EngineDescriptor engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "e");
DefaultJupiterConfiguration jupiterConfiguration = createJupiterConfiguration();
ClassTestDescriptor classTestDescriptor = new ClassTestDescriptor(UniqueId.forEngine("testClass"), TestClass.class,
jupiterConfiguration);
engineDescriptor.addChild(classTestDescriptor);
TestDescriptor testDescriptor = new TestFactoryTestDescriptor(UniqueId.forEngine("testMethod"), TestClass.class,
TestClass.class.getDeclaredMethod("brokenStream"),
jupiterConfiguration);
classTestDescriptor.addChild(testDescriptor);
TestIdentifier identifier = TestIdentifier.from(testDescriptor);
final TestPlan testPlan = TestPlan.from(Collections.singleton(engineDescriptor), EMPTY_PARAMETER);
myExecutionListener.setSendTree();
myExecutionListener.testPlanExecutionStarted(testPlan);
myExecutionListener.executionStarted(identifier);
myExecutionListener.executionFinished(identifier, TestExecutionResult.aborted(null));
Assertions.assertEquals("##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeStarted id='|[engine:testClass|]' name='JUnit5EventsTest$TestClass' nodeId='|[engine:testClass|]' parentNodeId='0' locationHint='java:suite://com.intellij.junit5.JUnit5EventsTest$TestClass']\n" +
"##teamcity[suiteTreeStarted id='|[engine:testMethod|]' name='brokenStream()' nodeId='|[engine:testMethod|]' parentNodeId='|[engine:testClass|]' locationHint='java:test://com.intellij.junit5.JUnit5EventsTest$TestClass/brokenStream' metainfo='']\n" +
"##teamcity[suiteTreeEnded id='|[engine:testMethod|]' name='brokenStream()' nodeId='|[engine:testMethod|]' parentNodeId='|[engine:testClass|]']\n" +
"##teamcity[suiteTreeEnded id='|[engine:testClass|]' name='JUnit5EventsTest$TestClass' nodeId='|[engine:testClass|]' parentNodeId='0']\n" +
"##teamcity[treeEnded]\n" +
"##teamcity[testSuiteStarted id='|[engine:testMethod|]' name='brokenStream()' nodeId='|[engine:testMethod|]' parentNodeId='|[engine:testClass|]'locationHint='java:test://com.intellij.junit5.JUnit5EventsTest$TestClass/brokenStream' metainfo='']\n" +
"##teamcity[testIgnored name='brokenStream()' id='|[engine:testMethod|]' nodeId='|[engine:testMethod|]' parentNodeId='|[engine:testClass|]']\n" +
"##teamcity[testSuiteFinished id='|[engine:testMethod|]' name='brokenStream()' nodeId='|[engine:testMethod|]' parentNodeId='|[engine:testClass|]']\n",
StringUtil.convertLineSeparators(myBuf.toString()));
}
// This class is actually the test-data
private static class TestClass {