mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
junit: insert Class Configuration node if after class/before class is failed. In case of before class, the rest of the tests should be marked as ignored (IDEA-148507)
This commit is contained in:
+83
-1
@@ -329,7 +329,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetupClassFailure() throws Exception {
|
||||
public void testSetupClassAssumptionFailure() throws Exception {
|
||||
final Description root = Description.createSuiteDescription("root");
|
||||
final Description testA = Description.createSuiteDescription("TestA");
|
||||
root.addChild(testA);
|
||||
@@ -362,6 +362,88 @@ public class JUnitTreeByDescriptionHierarchyTest {
|
||||
"\n" +
|
||||
"##teamcity[testFinished name='TestA.testName']\n" +
|
||||
"##teamcity[testSuiteFinished name='TestA']\n", StringUtil.convertLineSeparators(buf.toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetupClassFailure() throws Exception {
|
||||
final Description root = Description.createSuiteDescription("root");
|
||||
final Description testA = Description.createSuiteDescription("TestA");
|
||||
root.addChild(testA);
|
||||
final Description testName = Description.createTestDescription("TestA", "testName");
|
||||
testA.addChild(testName);
|
||||
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
final JUnit4TestListener sender = createListener(buf);
|
||||
sender.sendTree(root);
|
||||
|
||||
Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" +
|
||||
"##teamcity[suiteTreeStarted name='TestA' locationHint='java:suite://TestA']\n" +
|
||||
"##teamcity[suiteTreeNode name='TestA.testName' locationHint='java:test://TestA.testName']\n" +
|
||||
"##teamcity[suiteTreeEnded name='TestA']\n" +
|
||||
"##teamcity[treeEnded]\n", StringUtil.convertLineSeparators(buf.toString()));
|
||||
|
||||
buf.setLength(0);
|
||||
|
||||
sender.testRunStarted(testA);
|
||||
final Exception exception = new Exception();
|
||||
exception.setStackTrace(new StackTraceElement[0]);
|
||||
sender.testFailure(new Failure(testA, exception));
|
||||
sender.testRunFinished(new Result());
|
||||
|
||||
Assert.assertEquals("output: " + buf, "##teamcity[rootName name = 'root' location = 'java:suite://root']\n" +
|
||||
"##teamcity[testStarted name='Class Configuration' locationHint='java:suite://TestA' ]\n" +
|
||||
"\n" +
|
||||
"##teamcity[testFailed name='Class Configuration' details='java.lang.Exception|n' error='true' message='']\n" +
|
||||
"\n" +
|
||||
"##teamcity[testFinished name='Class Configuration']\n" +
|
||||
"##teamcity[testSuiteStarted name='TestA']\n" +
|
||||
"##teamcity[testStarted name='TestA.testName' locationHint='java:test://TestA.testName']\n" +
|
||||
"\n" +
|
||||
"##teamcity[testIgnored name='TestA.testName']\n" +
|
||||
"\n" +
|
||||
"##teamcity[testFinished name='TestA.testName']\n" +
|
||||
"##teamcity[testSuiteFinished name='TestA']\n", StringUtil.convertLineSeparators(buf.toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTearDownClassFailure() throws Exception {
|
||||
final Description root = Description.createSuiteDescription("root");
|
||||
final Description testA = Description.createSuiteDescription("TestA");
|
||||
root.addChild(testA);
|
||||
final Description testName = Description.createTestDescription("TestA", "testName");
|
||||
testA.addChild(testName);
|
||||
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
final JUnit4TestListener sender = createListener(buf);
|
||||
sender.sendTree(root);
|
||||
|
||||
Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" +
|
||||
"##teamcity[suiteTreeStarted name='TestA' locationHint='java:suite://TestA']\n" +
|
||||
"##teamcity[suiteTreeNode name='TestA.testName' locationHint='java:test://TestA.testName']\n" +
|
||||
"##teamcity[suiteTreeEnded name='TestA']\n" +
|
||||
"##teamcity[treeEnded]\n", StringUtil.convertLineSeparators(buf.toString()));
|
||||
|
||||
buf.setLength(0);
|
||||
|
||||
sender.testRunStarted(testA);
|
||||
final Exception exception = new Exception();
|
||||
exception.setStackTrace(new StackTraceElement[0]);
|
||||
sender.testStarted(testName);
|
||||
sender.testFinished(testName);
|
||||
sender.testFailure(new Failure(testA, exception));
|
||||
sender.testRunFinished(new Result());
|
||||
|
||||
Assert.assertEquals("output: " + buf, "##teamcity[rootName name = 'root' location = 'java:suite://root']\n" +
|
||||
"##teamcity[testSuiteStarted name='TestA']\n" +
|
||||
"##teamcity[testStarted name='TestA.testName' locationHint='java:test://TestA.testName']\n" +
|
||||
"\n" +
|
||||
"##teamcity[testFinished name='TestA.testName']\n" +
|
||||
"##teamcity[testStarted name='Class Configuration' locationHint='java:suite://TestA' ]\n" +
|
||||
"\n" +
|
||||
"##teamcity[testFailed name='Class Configuration' details='java.lang.Exception|n' error='true' message='']\n" +
|
||||
"\n" +
|
||||
"##teamcity[testFinished name='Class Configuration']\n" +
|
||||
"##teamcity[testSuiteFinished name='TestA']\n", StringUtil.convertLineSeparators(buf.toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -48,6 +48,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
private final PrintStream myPrintStream;
|
||||
private String myRootName;
|
||||
private long myCurrentTestStart;
|
||||
private int myFinishedCount = 0;
|
||||
|
||||
public JUnit4TestListener() {
|
||||
this(System.out);
|
||||
@@ -113,6 +114,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
|
||||
for (int i = myStartedSuites.size() - 1; i >= idx; i--) {
|
||||
currentClass = (Description)myStartedSuites.remove(i);
|
||||
myFinishedCount = 0;
|
||||
myPrintStream.println("##teamcity[testSuiteFinished name=\'" + escapeName(getShortName(JUnit4ReflectionUtil.getClassName(currentClass))) + "\']");
|
||||
}
|
||||
|
||||
@@ -121,7 +123,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
final String fqName = JUnit4ReflectionUtil.getClassName(descriptionFromHistory);
|
||||
final String className = getShortName(fqName);
|
||||
if (!className.equals(myRootName)) {
|
||||
myPrintStream.println("##teamcity[testSuiteStarted name=\'" + escapeName(className) + "\'" + (parents == null ? " locationHint=\'java:suite://" + escapeName(fqName) + "\'" : "") + "]");
|
||||
myPrintStream.println("##teamcity[testSuiteStarted name=\'" + escapeName(className) + "\'" + (parents == null ? getClassLocation(fqName) : "") + "]");
|
||||
myStartedSuites.add(descriptionFromHistory);
|
||||
}
|
||||
}
|
||||
@@ -131,6 +133,10 @@ public class JUnit4TestListener extends RunListener {
|
||||
myCurrentTestStart = currentTime();
|
||||
}
|
||||
|
||||
private static String getClassLocation(String fqName) {
|
||||
return " locationHint=\'java:suite://" + escapeName(fqName) + "\'";
|
||||
}
|
||||
|
||||
private static boolean isHierarchyDifferent(List parents,
|
||||
Description currentClass,
|
||||
Description currentParent) {
|
||||
@@ -149,6 +155,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
public void testFinished(Description description) throws Exception {
|
||||
final String methodName = getFullMethodName(description);
|
||||
if (methodName != null) {
|
||||
myFinishedCount++;
|
||||
final long duration = currentTime() - myCurrentTestStart;
|
||||
myPrintStream.println("\n##teamcity[testFinished name=\'" + escapeName(methodName) +
|
||||
(duration > 0 ? "\' duration=\'" + Long.toString(duration) : "") + "\']");
|
||||
@@ -160,10 +167,21 @@ public class JUnit4TestListener extends RunListener {
|
||||
}
|
||||
|
||||
private void testFailure(Failure failure, Description description, String messageName, boolean local) throws Exception {
|
||||
final String methodName = getFullMethodName(description);
|
||||
if (methodName == null) { //class setUp failed
|
||||
for (Iterator iterator = description.getChildren().iterator(); iterator.hasNext(); ) {
|
||||
testFailure(failure, (Description)iterator.next(), messageName, false);
|
||||
String methodName = getFullMethodName(description);
|
||||
if (methodName == null) { //class setUp/tearDown failed
|
||||
final boolean isIgnored = MapSerializerUtil.TEST_IGNORED.equals(messageName);
|
||||
if (!isIgnored) {
|
||||
methodName = "Class Configuration";
|
||||
myPrintStream.println("##teamcity[testStarted name=\'" + escapeName(methodName) + "\' " + getClassLocation(JUnit4ReflectionUtil.getClassName(description))+ " ]");
|
||||
testFailure(failure, messageName, methodName);
|
||||
myPrintStream.println("\n##teamcity[testFinished name=\'" + escapeName(methodName) + "\']");
|
||||
}
|
||||
|
||||
if (myFinishedCount == 0) {
|
||||
//only setup failures
|
||||
for (Iterator iterator = description.getChildren().iterator(); iterator.hasNext(); ) {
|
||||
testFailure(isIgnored ? failure : null, (Description)iterator.next(), MapSerializerUtil.TEST_IGNORED, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -181,10 +199,12 @@ public class JUnit4TestListener extends RunListener {
|
||||
attrs.put("duration", Long.toString(duration));
|
||||
}
|
||||
try {
|
||||
final String trace = getTrace(failure);
|
||||
final Throwable ex = failure.getException();
|
||||
final ComparisonFailureData notification = createExceptionNotification(ex);
|
||||
ComparisonFailureData.registerSMAttributes(notification, trace, failure.getMessage(), attrs, ex);
|
||||
if (failure != null) {
|
||||
final String trace = getTrace(failure);
|
||||
final Throwable ex = failure.getException();
|
||||
final ComparisonFailureData notification = createExceptionNotification(ex);
|
||||
ComparisonFailureData.registerSMAttributes(notification, trace, failure.getMessage(), attrs, ex);
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
final StringWriter stringWriter = new StringWriter();
|
||||
|
||||
Reference in New Issue
Block a user