Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xmlReportListener for beforeClass annotations #61

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading