From 0905ca385b16d769787182a2d32527b8c0d883f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Po=CC=88yho=CC=88nen?= Date: Thu, 15 Feb 2024 16:52:11 +0200 Subject: [PATCH] Fix xmlReportListener for beforeClass annotations --- .../test/junit/listeners/XMLReportListener.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/framework/src/play/test/junit/listeners/XMLReportListener.java b/framework/src/play/test/junit/listeners/XMLReportListener.java index e53c374c0c..d46a60b76e 100644 --- a/framework/src/play/test/junit/listeners/XMLReportListener.java +++ b/framework/src/play/test/junit/listeners/XMLReportListener.java @@ -32,6 +32,8 @@ public class XMLReportListener extends RunListener { private int problem; private long startTime; + private Description currentTest; + public XMLReportListener() { this(new XMLJUnitResultFormatter()); } @@ -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)); @@ -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