From 5fd8ec0cff37fdfb50a90aa546b0f1b69423acd2 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 15 Apr 2015 20:01:00 +0200 Subject: [PATCH] testng: do not include classes with method level configs in suite; include success/fail of configuration method --- .../testng/model/TestClassFilter.java | 2 +- .../testng/util/TestNGUtil.java | 27 ++++++++++++++++--- .../org/testng/IDEATestNGRemoteListener.java | 19 +++++++++---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/plugins/testng/src/com/theoryinpractice/testng/model/TestClassFilter.java b/plugins/testng/src/com/theoryinpractice/testng/model/TestClassFilter.java index 6570b55b53af..b7f3219a0a72 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/model/TestClassFilter.java +++ b/plugins/testng/src/com/theoryinpractice/testng/model/TestClassFilter.java @@ -94,7 +94,7 @@ public class TestClassFilter implements ClassFilter.ClassFilterWithScope return true; } - return includeConfig && TestNGUtil.hasConfig(psiClass); + return includeConfig && TestNGUtil.hasConfig(psiClass, TestNGUtil.CONFIG_ANNOTATIONS_FQN_NO_TEST_LEVEL); } }); } diff --git a/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java b/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java index 4c11b23b6575..38fd89d5e695 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java +++ b/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java @@ -90,6 +90,20 @@ public class TestNGUtil { AfterTest.class.getName() }; + @SuppressWarnings("deprecation") public static final String[] CONFIG_ANNOTATIONS_FQN_NO_TEST_LEVEL = { + Configuration.class.getName(), + Factory.class.getName(), + ObjectFactory.class.getName(), + BeforeClass.class.getName(), + BeforeGroups.class.getName(), + BeforeSuite.class.getName(), + BeforeTest.class.getName(), + AfterClass.class.getName(), + AfterGroups.class.getName(), + AfterSuite.class.getName(), + AfterTest.class.getName() + }; + @NonNls private static final String[] CONFIG_JAVADOC_TAGS = { "testng.configuration", @@ -112,19 +126,24 @@ public class TestNGUtil { private static final String SUITE_TAG_NAME = "suite"; public static boolean hasConfig(PsiModifierListOwner element) { + return hasConfig(element, CONFIG_ANNOTATIONS_FQN); + } + + public static boolean hasConfig(PsiModifierListOwner element, + String[] configAnnotationsFqn) { if (element instanceof PsiClass) { for (PsiMethod method : ((PsiClass)element).getAllMethods()) { - if (isConfigMethod(method)) return true; + if (isConfigMethod(method, configAnnotationsFqn)) return true; } } else { if (!(element instanceof PsiMethod)) return false; - return isConfigMethod((PsiMethod)element); + return isConfigMethod((PsiMethod)element, configAnnotationsFqn); } return false; } - private static boolean isConfigMethod(PsiMethod method) { - for (String fqn : CONFIG_ANNOTATIONS_FQN) { + private static boolean isConfigMethod(PsiMethod method, String[] configAnnotationsFqn) { + for (String fqn : configAnnotationsFqn) { if (AnnotationUtil.isAnnotated(method, fqn, false)) return true; } diff --git a/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java b/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java index 4a3d76543e1b..303ae5bc6125 100644 --- a/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java +++ b/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java @@ -21,16 +21,25 @@ public class IDEATestNGRemoteListener implements ISuiteListener, IResultListener private String myMethodName; private int myInvocationCount = 0; - public void onConfigurationSuccess(ITestResult itr) { - //won't be called + public void onConfigurationSuccess(ITestResult result) { + final String className = result.getTestClass().getName(); + System.out.println("##teamcity[testSuiteStarted name=\'" + className + "\']"); + final String methodName = result.getMethod().getMethodName(); + System.out.println("##teamcity[testStarted name=\'" + methodName + "\']"); + onTestSuccess(result); + System.out.println("\n##teamcity[testSuiteFinished name=\'" + className + "\']"); } - public void onConfigurationFailure(ITestResult itr) { - //won't be called + public void onConfigurationFailure(ITestResult result) { + final String className = result.getTestClass().getName(); + System.out.println("##teamcity[testSuiteStarted name=\'" + className + "\']"); + final String methodName = result.getMethod().getMethodName(); + System.out.println("##teamcity[testStarted name=\'" + methodName + "\']"); + onTestFailure(result); + System.out.println("\n##teamcity[testSuiteFinished name=\'" + className + "\']"); } public void onConfigurationSkip(ITestResult itr) { - //won't be called } public void onStart(ISuite suite) {