The Artima Developer Community
Sponsored Link

ScalaTest/ScalaUtils Forum
Problem with XML testreport generation

2 replies on 1 page. Most recent reply: Jun 23, 2014 3:27 AM by Dominik Haneberg

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
    Next Topic
Flat View: This topic has 2 replies on 1 page
Dominik Haneberg

Posts: 2
Nickname: haneberg
Registered: Jun, 2014

Problem with XML testreport generation Posted: Jun 20, 2014 10:24 AM
Reply to this message Reply
Advertisement
I have a problem with the generation of XML test results. I use my own subclass of FunSuite which contains the testcases:

class MyFunSuite(val range:Range, name:String) extends FunSuite {
range.foreach((i:Int) => {
test(name + ":"+i) {
assert(i == i)
}
}
)
}

MyFunSuite takes a parameter and constructs its testcases based on the value of the parameter.

Then I have a Suite which contains two (or more) instances of MyFunSuite as nested suites:

class AllTests extends Sequential(new MyFunSuite((1 until 10), "Range 1") , new MyFunSuite((30 until 35), "Range 2"))

When I execute AllTests, e.g. with sbt (> test-only tests.error.AllTests), sbt reports successful runs:
[info] Run completed in 383 milliseconds.
[info] Total number of tests run: 14
[info] Suites: completed 3, aborted 0
[info] Tests: succeeded 14, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.

But when I look for the XML-output, I am missing reports on testcases. First of all, I only see an XML-file for the second instance of MyFunSuite but not for the first. I guess it gets overwritten(?) as the filename for the report seems to be per class not per instance. Furthermore the test report for AllTests says it does not contain any tests at all:
<testsuite errors="0" failures="0" hostname="xubuntu" name="tests.error.AllTests" tests="0" time="0.148" timestamp="2014-06-20T14:52:57" ...

I would have expected the testcases of the nested suites to count towards the number of tests of the complete suite. The problem with the behaviour as it is is that this confuses Jenkins as it thinks that I do not have any testcases.

Am I making a conceptual error here or is this a potential bug?

For completeness, my build.sbt definition is:
name := "TestsuiteError"

scalaVersion := "2.10.3"

version := "6"

libraryDependencies ++= Seq(
"junit" % "junit" % "4.8.2" ,
"org.scalatest" % "scalatest_2.10" % "2.0"
)

scalaSource in Compile <<= baseDirectory(_ / "src")

scalaSource in Test <<= baseDirectory(_ / "src")

javacOptions ++= Seq("-encoding", "ISO8859-1")

scalacOptions ++= Seq("-encoding", "ISO8859-1")

testOptions in Test <+= (target in Test) map {
t => Tests.Argument("-u", "test-reports")
}


Bill Venners

Posts: 2249
Nickname: bv
Registered: Jan, 2002

Re: Problem with XML testreport generation Posted: Jun 20, 2014 2:03 PM
Reply to this message Reply
You'll need to override suiteId and provide a unique suiteId for each nested suite. By default the suiteId is the fully qualified name of the class, and in this case you have two instances of that class. The XML reporter will write a file for both nested suites, but the second one will overwrite the first one, because it has the same name. This should work:


package com.example

import org.scalatest._

class MyFunSuite(val range: Range, name: String) extends FunSuite {

range.foreach { (i:Int) =>
test(name + ":" + i) {
assert(i == i)
}
}

override def suiteId = this.getClass.getName + "." + name.filterNot(_.isWhitespace)
}

class AllTests extends Sequential(new MyFunSuite((1 until 10), "Range 1") , new MyFunSuite((30 until 35), "Range 2"))

Dominik Haneberg

Posts: 2
Nickname: haneberg
Registered: Jun, 2014

Re: Problem with XML testreport generation Posted: Jun 23, 2014 3:27 AM
Reply to this message Reply
That did the trick. Thank you very much!

Flat View: This topic has 2 replies on 1 page
    Next Topic Topic: Visibility and ScalaTest


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us