Port tests/junit-xml-report

This commit is contained in:
Eugene Yokota 2016-03-29 02:28:48 -04:00
parent ef511d7582
commit 1a8149568e
2 changed files with 38 additions and 42 deletions

View File

@ -0,0 +1,38 @@
import scala.xml.XML
import Tests._
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"
lazy val root = (project in file(".")).
settings(
scalaVersion := "2.9.2",
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test",
// TODO use matchers instead of sys.error
checkReport := {
val oneSecondReport = XML.loadFile(oneSecondReportFile)
if( oneSecondReport.label != "testsuite" ) sys.error("Report should have a root <testsuite> element.")
// somehow the 'success' event doesn't go through... TODO investigate
// if( (oneSecondReport \ "@time").text.toFloat < 1f ) sys.error("expected test to take at least 1 sec")
if( (oneSecondReport \ "@name").text != "a.pkg.OneSecondTest" ) sys.error("wrong test name: " + (oneSecondReport \ "@name").text)
// TODO more checks
val failingReport = XML.loadFile(failingReportFile)
if( failingReport.label != "testsuite" ) sys.error("Report should have a root <testsuite> element.")
if( (failingReport \ "@failures").text != "2" ) sys.error("expected 2 failures")
if( (failingReport \ "@name").text != "another.pkg.FailingTest" ) sys.error("wrong test name: " + (failingReport \ "@name").text)
// TODO more checks -> the two test cases with time etc..
// TODO check console output is in the report
},
checkNoReport := {
if( file(oneSecondReportFile).exists() ) sys.error(oneSecondReportFile + " should not exist")
if( file(failingReportFile).exists() ) sys.error(failingReportFile + " should not exist")
}
)

View File

@ -1,42 +0,0 @@
import sbt._
import Keys._
import scala.xml.XML
import Tests._
import Defaults._
import Import._
object JUnitXmlReportTest extends Build {
val checkReport = taskKey[Unit]("Check the test reports")
val checkNoReport = taskKey[Unit]("Check that no reports are present")
private val oneSecondReportFile = "target/test-reports/a.pkg.OneSecondTest.xml"
private val failingReportFile = "target/test-reports/another.pkg.FailingTest.xml"
lazy val root = Project("root", file("."), settings = defaultSettings ++ Seq(
scalaVersion := "2.9.2",
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test",
// TODO use matchers instead of sys.error
checkReport := {
val oneSecondReport = XML.loadFile(oneSecondReportFile)
if( oneSecondReport.label != "testsuite" ) sys.error("Report should have a root <testsuite> element.")
// somehow the 'success' event doesn't go through... TODO investigate
// if( (oneSecondReport \ "@time").text.toFloat < 1f ) sys.error("expected test to take at least 1 sec")
if( (oneSecondReport \ "@name").text != "a.pkg.OneSecondTest" ) sys.error("wrong test name: " + (oneSecondReport \ "@name").text)
// TODO more checks
val failingReport = XML.loadFile(failingReportFile)
if( failingReport.label != "testsuite" ) sys.error("Report should have a root <testsuite> element.")
if( (failingReport \ "@failures").text != "2" ) sys.error("expected 2 failures")
if( (failingReport \ "@name").text != "another.pkg.FailingTest" ) sys.error("wrong test name: " + (failingReport \ "@name").text)
// TODO more checks -> the two test cases with time etc..
// TODO check console output is in the report
},
checkNoReport := {
if( file(oneSecondReportFile).exists() ) sys.error(oneSecondReportFile + " should not exist")
if( file(failingReportFile).exists() ) sys.error(failingReportFile + " should not exist")
}
))
}