From 9cf9d65cf6e1d6aca7f9e383e84e614aa9a79e7a Mon Sep 17 00:00:00 2001 From: Sergey Ignatov Date: Thu, 25 Oct 2018 15:47:20 +0300 Subject: [PATCH] introduce ExcludeFromTestDiscovery annotation allow excluding some test from test discovery capturing for example, when they both are trying to manipulate with byte code --- .../core/src/com/intellij/TestCaseLoader.java | 8 +++++++- .../com/intellij/idea/ExcludeFromTestDiscovery.java | 12 ++++++++++++ .../intellij/coverage/CoverageIntegrationTest.java | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 platform/testFramework/core/src/com/intellij/idea/ExcludeFromTestDiscovery.java diff --git a/platform/testFramework/core/src/com/intellij/TestCaseLoader.java b/platform/testFramework/core/src/com/intellij/TestCaseLoader.java index 2ac21e55407f..04b00f563a9c 100644 --- a/platform/testFramework/core/src/com/intellij/TestCaseLoader.java +++ b/platform/testFramework/core/src/com/intellij/TestCaseLoader.java @@ -3,6 +3,7 @@ package com.intellij; import com.intellij.idea.Bombed; +import com.intellij.idea.ExcludeFromTestDiscovery; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.testFramework.RunFirst; @@ -36,6 +37,7 @@ public class TestCaseLoader { private static final boolean INCLUDE_PERFORMANCE_TESTS = "true".equals(System.getProperty(INCLUDE_PERFORMANCE_TESTS_FLAG)); private static final boolean INCLUDE_UNCONVENTIONALLY_NAMED_TESTS = "true".equals(System.getProperty(INCLUDE_UNCONVENTIONALLY_NAMED_TESTS_FLAG)); private static final boolean RUN_ONLY_AFFECTED_TESTS = "true".equals(System.getProperty(RUN_ONLY_AFFECTED_TEST_FLAG)); + private static final boolean RUN_WITH_TEST_DISCOVERY = System.getProperty("test.discovery.listener") != null; /** * An implicit group which includes all tests from all defined groups and tests which don't belong to any group. @@ -173,7 +175,11 @@ public class TestCaseLoader { if (!myForceLoadPerformanceTests && !shouldIncludePerformanceTestCase(testCaseClass)) return true; String className = testCaseClass.getName(); - return !myTestClassesFilter.matches(className, moduleName) || isBombed(testCaseClass); + return !myTestClassesFilter.matches(className, moduleName) || isBombed(testCaseClass) || isExcludeFromTestDiscovery(testCaseClass); + } + + private static boolean isExcludeFromTestDiscovery(Class c) { + return RUN_WITH_TEST_DISCOVERY && getAnnotationInHierarchy(c, ExcludeFromTestDiscovery.class) != null; } public static boolean isBombed(final AnnotatedElement element) { diff --git a/platform/testFramework/core/src/com/intellij/idea/ExcludeFromTestDiscovery.java b/platform/testFramework/core/src/com/intellij/idea/ExcludeFromTestDiscovery.java new file mode 100644 index 000000000000..c025bc29f637 --- /dev/null +++ b/platform/testFramework/core/src/com/intellij/idea/ExcludeFromTestDiscovery.java @@ -0,0 +1,12 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.idea; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE}) +public @interface ExcludeFromTestDiscovery { +} \ No newline at end of file diff --git a/plugins/coverage/testSrc/com/intellij/coverage/CoverageIntegrationTest.java b/plugins/coverage/testSrc/com/intellij/coverage/CoverageIntegrationTest.java index 474fea654d22..000304c5aaeb 100644 --- a/plugins/coverage/testSrc/com/intellij/coverage/CoverageIntegrationTest.java +++ b/plugins/coverage/testSrc/com/intellij/coverage/CoverageIntegrationTest.java @@ -15,6 +15,7 @@ */ package com.intellij.coverage; +import com.intellij.idea.ExcludeFromTestDiscovery; import com.intellij.openapi.application.PluginPathManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.ex.ProjectManagerEx; @@ -32,6 +33,7 @@ import java.util.Map; /** * @author yole */ +@ExcludeFromTestDiscovery public class CoverageIntegrationTest extends ModuleTestCase { private static String getTestDataPath() { return PluginPathManager.getPluginHomePath("coverage") + "/testData/simple";