diff --git a/main/src/main/scala/sbt/internal/SysProp.scala b/main/src/main/scala/sbt/internal/SysProp.scala index bbd0785a2..557fadb2d 100644 --- a/main/src/main/scala/sbt/internal/SysProp.scala +++ b/main/src/main/scala/sbt/internal/SysProp.scala @@ -70,6 +70,7 @@ object SysProp { def client: Boolean = getOrFalse("sbt.client") def ci: Boolean = getOrFalse("sbt.ci") def allowRootDir: Boolean = getOrFalse("sbt.rootdir") + def legacyTestReport: Boolean = getOrFalse("sbt.testing.legacyreport") def watchMode: String = sys.props.get("sbt.watch.mode").getOrElse("auto") diff --git a/main/src/main/scala/sbt/plugins/JUnitXmlReportPlugin.scala b/main/src/main/scala/sbt/plugins/JUnitXmlReportPlugin.scala index 842c8dd76..39baa07a6 100644 --- a/main/src/main/scala/sbt/plugins/JUnitXmlReportPlugin.scala +++ b/main/src/main/scala/sbt/plugins/JUnitXmlReportPlugin.scala @@ -10,6 +10,7 @@ package plugins import Def.Setting import Keys._ +import sbt.internal.SysProp /** * An experimental plugin that adds the ability for junit-xml to be generated. @@ -30,6 +31,10 @@ object JUnitXmlReportPlugin extends AutoPlugin { // It might be a good idea to derive this setting into specific test scopes. override lazy val projectSettings: Seq[Setting[_]] = Seq( - testListeners += new JUnitXmlTestsListener(target.value.getAbsolutePath, streams.value.log) + testListeners += new JUnitXmlTestsListener( + target.value.getAbsolutePath, + SysProp.legacyTestReport, + streams.value.log + ) ) } diff --git a/sbt/src/sbt-test/tests/junit-xml-report/build.sbt b/sbt/src/sbt-test/tests/junit-xml-report/build.sbt index 1d864c81b..a2f002d50 100644 --- a/sbt/src/sbt-test/tests/junit-xml-report/build.sbt +++ b/sbt/src/sbt-test/tests/junit-xml-report/build.sbt @@ -5,11 +5,11 @@ import Defaults._ val checkReport = taskKey[Unit]("Check the test reports") val checkNoReport = taskKey[Unit]("Check that no reports are present") -val oneSecondReportFile = "target/test-reports/a.pkg.OneSecondTest.xml" -val failingReportFile = "target/test-reports/another.pkg.FailingTest.xml" +val oneSecondReportFile = "target/test-reports/TEST-a.pkg.OneSecondTest.xml" +val failingReportFile = "target/test-reports/TEST-another.pkg.FailingTest.xml" -val flatSuiteReportFile = "target/test-reports/my.scalatest.MyFlatSuite.xml" -val nestedSuitesReportFile = "target/test-reports/my.scalatest.MyNestedSuites.xml" +val flatSuiteReportFile = "target/test-reports/TEST-my.scalatest.MyFlatSuite.xml" +val nestedSuitesReportFile = "target/test-reports/TEST-my.scalatest.MyNestedSuites.xml" val scalatest = "org.scalatest" %% "scalatest" % "3.0.5" val junitinterface = "com.novocode" % "junit-interface" % "0.11" diff --git a/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala b/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala index cb8db7338..d8e0bfa2b 100644 --- a/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala +++ b/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala @@ -33,9 +33,11 @@ import sbt.protocol.testing.TestResult * report format. * @param outputDir path to the dir in which a folder with results is generated */ -class JUnitXmlTestsListener(val outputDir: String, logger: Logger) extends TestsListener { - // This constructor is for binary compatibility with older versions of sbt. - def this(outputDir: String) = this(outputDir, null) +class JUnitXmlTestsListener(val outputDir: String, legacyTestReport: Boolean, logger: Logger) + extends TestsListener { + // These constructors are for binary compatibility with older versions of sbt. + def this(outputDir: String, logger: Logger) = this(outputDir, false, logger) + def this(outputDir: String) = this(outputDir, false, null) /**Current hostname so we know which machine executed the tests*/ val hostname: String = { @@ -248,14 +250,14 @@ class JUnitXmlTestsListener(val outputDir: String, logger: Logger) extends Tests d.truncatedTo(ChronoUnit.SECONDS).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) private def writeSuite(): Unit = { - val legacyFile = + val file = if (legacyTestReport) { new File(targetDir, s"${normalizeName(withTestSuite(_.name))}.xml").getAbsolutePath - val file = + } else { new File(targetDir, s"TEST-${normalizeName(withTestSuite(_.name))}.xml").getAbsolutePath + } // TODO would be nice to have a logger and log this with level debug // System.err.println("Writing JUnit XML test report: " + file) val testSuiteResult = withTestSuite(_.stop()) - XML.save(legacyFile, testSuiteResult, "UTF-8", xmlDecl = true, null) XML.save(file, testSuiteResult, "UTF-8", xmlDecl = true, null) testSuite.remove() }