From 60839e473a15032182c3dc994cdcce6b3ba54c1c Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 25 Jun 2015 16:00:36 +0300 Subject: [PATCH] testng: provide navigation to xml suite (IDEA-140884) --- .../sm/TestsLocationProviderUtil.java | 3 +- .../TestNGTreeHierarchyTest.java | 11 ++++++ .../org/testng/IDEATestNGRemoteListener.java | 35 ++++++++++++++++--- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/TestsLocationProviderUtil.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/TestsLocationProviderUtil.java index f0452412a59f..dbc74c167467 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/TestsLocationProviderUtil.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/TestsLocationProviderUtil.java @@ -81,7 +81,8 @@ public class TestsLocationProviderUtil { if (fileName == null) { return Collections.emptyList(); } - return findFilesClosestToTarget(folders, collectCandidates(project, fileName, true), MIN_PROXIMITY_THRESHOLD); + final List target = findFilesClosestToTarget(folders, collectCandidates(project, fileName, true), MIN_PROXIMITY_THRESHOLD); + return target.isEmpty() && file != null ? Collections.singletonList(file) : target; } /** diff --git a/plugins/testng/testSources/com/theoryinpractice/testng/configuration/TestNGTreeHierarchyTest.java b/plugins/testng/testSources/com/theoryinpractice/testng/configuration/TestNGTreeHierarchyTest.java index b89434a5df4f..e9060819f7b5 100644 --- a/plugins/testng/testSources/com/theoryinpractice/testng/configuration/TestNGTreeHierarchyTest.java +++ b/plugins/testng/testSources/com/theoryinpractice/testng/configuration/TestNGTreeHierarchyTest.java @@ -32,6 +32,7 @@ import java.io.OutputStream; import java.io.PrintStream; import java.util.Arrays; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; public class TestNGTreeHierarchyTest { @@ -388,6 +389,16 @@ public class TestNGTreeHierarchyTest { return Collections.singletonList(myClassName); } + @Override + public String getFileName() { + return null; + } + + @Override + public String getXmlTestName() { + return null; + } + @Override public Throwable getThrowable() { return myThrowable; diff --git a/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java b/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java index 6ce51491d450..aec42c8bc4ca 100644 --- a/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java +++ b/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java @@ -30,6 +30,9 @@ public class IDEATestNGRemoteListener implements ISuiteListener, IResultListener public synchronized void onStart(final ISuite suite) { myPrintStream.println("##teamcity[enteredTheMatrix]"); + if (suite != null) { + myPrintStream.println("##teamcity[rootName name = '" + suite.getName() + "' location = 'file://" + suite.getXmlSuite().getFileName() + "']"); + } } public synchronized void onFinish(ISuite suite) { @@ -101,10 +104,10 @@ public class IDEATestNGRemoteListener implements ISuiteListener, IResultListener } public boolean onSuiteStart(String classFQName, boolean provideLocation) { - return onSuiteStart(Collections.singletonList(classFQName), provideLocation); + return onSuiteStart(Collections.singletonList(classFQName), null, provideLocation); } - public boolean onSuiteStart(List parentsHierarchy, boolean provideLocation) { + public boolean onSuiteStart(List parentsHierarchy, ExposedTestResult result, boolean provideLocation) { int idx = 0; String currentClass; String currentParent; @@ -123,8 +126,18 @@ public class IDEATestNGRemoteListener implements ISuiteListener, IResultListener for (int i = idx; i < parentsHierarchy.size(); i++) { String fqName = parentsHierarchy.get(parentsHierarchy.size() - 1 - i); String currentClassName = getShortName(fqName); + String location = "java:suite://" + escapeName(fqName); + if (result != null) { + final String testName = result.getXmlTestName(); + if (fqName.equals(testName)) { + final String fileName = result.getFileName(); + if (fileName != null) { + location = "file://" + fileName; + } + } + } myPrintStream.println("\n##teamcity[testSuiteStarted name =\'" + escapeName(currentClassName) + - (provideLocation ? "\' locationHint = \'java:suite://" + escapeName(fqName) : "") + "\']"); + (provideLocation ? "\' locationHint = \'" + location : "") + "\']"); myCurrentSuites.add(currentClassName); } return false; @@ -137,8 +150,7 @@ public class IDEATestNGRemoteListener implements ISuiteListener, IResultListener private void onTestStart(ExposedTestResult result, String paramString, Integer invocationCount) { myPrintStream.println("##teamcity[testCount count=\'1\']"); myParamsMap.put(result, paramString); - final List fqns = result.getTestHierarchy(); - onSuiteStart(fqns, true); + onSuiteStart(result.getTestHierarchy(), result, true); final String className = result.getClassName(); final String methodName = result.getMethodName(); final String location = className + "." + methodName + (invocationCount >= 0 ? "[" + invocationCount + "]" : ""); @@ -236,6 +248,8 @@ public class IDEATestNGRemoteListener implements ISuiteListener, IResultListener String getClassName(); long getDuration(); List getTestHierarchy(); + String getFileName(); + String getXmlTestName(); Throwable getThrowable(); } @@ -273,6 +287,17 @@ public class IDEATestNGRemoteListener implements ISuiteListener, IResultListener return hierarchy; } + public String getFileName() { + final XmlTest xmlTest = myResult.getTestClass().getXmlTest(); + return xmlTest != null ? xmlTest.getSuite().getFileName() : null; + } + + public String getXmlTestName() { + final XmlTest xmlTest = myResult.getTestClass().getXmlTest(); + return xmlTest != null ? xmlTest.getName() : null; + } + + public Throwable getThrowable() { return myResult.getThrowable(); }