I am trying to run a set of tests on multiple XML documents. I want to get a list of product IDs from a config file, and then run the same set of tests on every document. However, when I do this, I cannot get a single final summary of the test stats.
Sample code is below:
import org.scalatest._
import org.scalatest.matchers.ShouldMatchers._
import scala.xml._
import dispatch._
class xyzSpec(webcli: Http, productId: String) extends FeatureSpec with GivenWhenThen with ShouldMatchers {
feature("We get up to date xyz data from xyzsystem with correct blahblah info") {
info("As a programmer")
info("I want to lookup a product in xyzsystem")
info("So that I can check the date updated and blahblah info")
scenario("We have an up to date product with correct blahblah info") {
given("Product " + productId)
// code to get product XML doc
when("when we request the db record")
// code to get crosscheck data from SQL db
then("we can get the product record")
// code to compare date updated
and("date updated in the XML matches the SQL db")
}
}
}
val h = new Http
val TestConfXml = h(qaz <> identity)
ProdIdsXml \\ "product" foreach { (product) =>
val productId = (product \ "@id").text
new xyzSpec(h, productId).execute(stats=true)
}
The third last line has a foreach which invokes the test runner multiple times. I know that I can nest test objects (or is that test classes) but I cannot see how to do this dynamically at runtime, when the test class constructor takes parameters.
What am I missing?
Rather than call execute on each suite you create, just collect them then return them from nestedSuites of a suite. And call execute on that outer suite.
Voila!