我正在尝试对多个 XML 文档运行一组测试。我想从配置文件中获取产品 ID 列表,然后在每个文档上运行相同的测试集。但是,当我这样做时,我无法获得测试统计数据的最终摘要。
示例代码如下:
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)
}
最后第三行有 aforeach
多次调用测试运行器。我知道我可以嵌套测试对象(或者是测试类),但是当测试类构造函数接受参数时,我看不到如何在运行时动态地执行此操作。
我错过了什么?