testng: provide navigation to xml suite (IDEA-140884)

This commit is contained in:
Anna Kozlova
2015-06-25 20:58:18 +03:00
parent 775841976e
commit 60839e473a
3 changed files with 43 additions and 6 deletions
@@ -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<VirtualFile> target = findFilesClosestToTarget(folders, collectCandidates(project, fileName, true), MIN_PROXIMITY_THRESHOLD);
return target.isEmpty() && file != null ? Collections.singletonList(file) : target;
}
/**
@@ -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;
@@ -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<String> parentsHierarchy, boolean provideLocation) {
public boolean onSuiteStart(List<String> 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<String> 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<String> 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();
}