Skip to content

Commit

Permalink
Merge pull request #61 from Nosto/bugfix/fix-junit-xmllistener-for-be…
Browse files Browse the repository at this point in the history
…foreClass

Fix xmlReportListener for beforeClass annotations
  • Loading branch information
anttip authored Feb 15, 2024
2 parents 42dda25 + 0905ca3 commit dd1a604
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions framework/src/play/test/junit/listeners/XMLReportListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class XMLReportListener extends RunListener {
private int problem;
private long startTime;

private Description currentTest;

public XMLReportListener() {
this(new XMLJUnitResultFormatter());
}
Expand All @@ -52,6 +54,7 @@ public void testRunFinished(Result result) {

@Override
public void testStarted(Description description) throws Exception {
this.currentTest = description;
formatter.setOutput(new FileOutputStream(new File("test-result", "TEST-" + description.getClassName() + "-" + description.getMethodName() + ".xml")));
formatter.startTestSuite(new JUnitTest(description.getDisplayName()));
formatter.startTest(JUnit4TestAdapterCache.getDefault().asTest(description));
Expand Down Expand Up @@ -79,11 +82,19 @@ public void testFinished(Description description) {
suite.setCounts(1, problem, 0);
suite.setRunTime(System.currentTimeMillis() - startTime);
formatter.endTestSuite(suite);
this.currentTest = null;
}

@Override
public void testFailure(Failure failure) {
testAssumptionFailure(failure);
public void testFailure(Failure failure) throws Exception{
if ( currentTest == null ){
// if failure happens in beforeClass then any tests hasn't started, so mimic the start and end of the test
testStarted(failure.getDescription());
testAssumptionFailure(failure);
testFinished(failure.getDescription());
} else {
testAssumptionFailure(failure);
}
}

@Override
Expand Down

0 comments on commit dd1a604

Please sign in to comment.