Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-6700] Failure in test class constructor or @before met…
…hod was not reported
  • Loading branch information
kutzi committed Jul 23, 2011
1 parent 343d3ac commit a2c8673
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -69,6 +69,9 @@
<li class=bug>
Fixed Maven build error if headless option is set and MAVEN_OPTS empty
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-10375">issue 10375</a>)
<li class=bug>
Tests not recognized as failed if test initialization failed
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-6700">issue 6700</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
9 changes: 5 additions & 4 deletions core/src/main/java/hudson/tasks/junit/SuiteResult.java
Expand Up @@ -123,7 +123,8 @@ private static void parseSuite(File xmlReport, boolean keepLongStdio, List<Suite
parseSuite(xmlReport, keepLongStdio, r, suite);

// child test cases
if (root.element("testcase")!=null)
// FIXME: do this also if no testcases!
if (root.element("testcase")!=null || root.element("error")!=null)
r.add(new SuiteResult(xmlReport, root, keepLongStdio));
}

Expand Down Expand Up @@ -155,11 +156,11 @@ private SuiteResult(File xmlReport, Element suite, boolean keepLongStdio) throws
}

for (Element e : (List<Element>)suite.elements("testcase")) {
// https://hudson.dev.java.net/issues/show_bug.cgi?id=1233 indicates that
// https://issues.jenkins-ci.org/browse/JENKINS-1233 indicates that
// when <testsuites> is present, we are better off using @classname on the
// individual testcase class.

// https://hudson.dev.java.net/issues/show_bug.cgi?id=1463 indicates that
// https://issues.jenkins-ci.org/browse/JENKINS-1463 indicates that
// @classname may not exist in individual testcase elements. We now
// also test if the testsuite element has a package name that can be used
// as the class name instead of the file name which is default.
Expand All @@ -168,7 +169,7 @@ private SuiteResult(File xmlReport, Element suite, boolean keepLongStdio) throws
classname = suite.attributeValue("name");
}

// https://hudson.dev.java.net/issues/show_bug.cgi?id=1233 and
// https://issues.jenkins-ci.org/browse/JENKINS-1233 and
// http://www.nabble.com/difference-in-junit-publisher-and-ant-junitreport-tf4308604.html#a12265700
// are at odds with each other --- when both are present,
// one wants to use @name from <testsuite>,
Expand Down
25 changes: 21 additions & 4 deletions test/src/test/java/hudson/tasks/junit/SuiteResultTest.java 100755 → 100644
Expand Up @@ -27,23 +27,25 @@
import java.util.List;
import java.net.URISyntaxException;

import junit.framework.TestCase;

import hudson.XmlFile;
import org.jvnet.hudson.test.HudsonTestCase;

import org.jvnet.hudson.test.Bug;

import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.Writer;

import junit.framework.TestCase;

/**
* Test cases for parsing JUnit report XML files.
* As there are no XML schema for JUnit xml files, Hudson needs to handle
* varied xml files.
*
* @author Erik Ramfelt
* @author Christoph Kutzinski
*/
public class SuiteResultTest extends HudsonTestCase {
public class SuiteResultTest extends TestCase {

private File getDataFile(String name) throws URISyntaxException {
return new File(SuiteResultTest.class.getResource(name).toURI());
Expand Down Expand Up @@ -179,4 +181,19 @@ public void testSuiteStdioTrimming() throws Exception {
}
}


/**
* When the testcase fails to initialize (exception in constructor or @Before)
* there is no 'testcase' element at all.
*/
@Bug(6700)
public void testErrorInTestInitialization() throws Exception {
SuiteResult suiteResult = parseOne(getDataFile("junit-report-6700.xml"));

assertEquals(1, suiteResult.getCases().size());

CaseResult result = suiteResult.getCases().get(0);
assertEquals(1, result.getFailCount());
assertTrue(result.getErrorStackTrace() != null);
}
}

0 comments on commit a2c8673

Please sign in to comment.