From 940f19a86179e8bd21fc17bc2b25cb9942f520ba Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 16 Nov 2021 21:38:08 +0100 Subject: [PATCH] [junit 5] support for ignored containers (IDEA-204995) GitOrigin-RevId: 0b7f9a023e204a45f0a0079552a869066f72ddee --- .../junit5/JUnit5TestExecutionListener.java | 21 +++---------- .../com/intellij/junit5/JUnit5EventsTest.java | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/plugins/junit5_rt/src/com/intellij/junit5/JUnit5TestExecutionListener.java b/plugins/junit5_rt/src/com/intellij/junit5/JUnit5TestExecutionListener.java index 6e53fc77b5fd..c7ae8c431155 100644 --- a/plugins/junit5_rt/src/com/intellij/junit5/JUnit5TestExecutionListener.java +++ b/plugins/junit5_rt/src/com/intellij/junit5/JUnit5TestExecutionListener.java @@ -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 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 descendants = myTestPlan != null ? myTestPlan.getDescendants(testIdentifier) : Collections.emptySet(); if (!descendants.isEmpty() && myFinishCount == 0) { for (TestIdentifier childIdentifier : descendants) { testStarted(childIdentifier); 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 2aa5c9a8bb6c..a25d8348c155 100644 --- a/plugins/junit5_rt_tests/test/com/intellij/junit5/JUnit5EventsTest.java +++ b/plugins/junit5_rt_tests/test/com/intellij/junit5/JUnit5EventsTest.java @@ -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 {