0

複数の XML ドキュメントに対して一連のテストを実行しようとしています。構成ファイルから製品 ID のリストを取得し、すべてのドキュメントに対して同じ一連のテストを実行したいと考えています。ただし、これを行うと、テスト統計の最終的な要約を 1 つも取得できません。

サンプルコードは次のとおりです。

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)        

}

最後から 3 行目foreachには、テスト ランナーを複数回呼び出す a があります。テスト オブジェクトをネストできる (またはテスト クラスをテストする) ことはわかっていますが、テスト クラス コンストラクターがパラメーターを受け取るときに、実行時にこれを動的に行う方法がわかりません。

私は何が欠けていますか?

4

1 に答える 1

1

作成するスイートごとに execute を呼び出すのではなく、それらを収集して、スイートのネストされたスイートから返します。そして、その外側のスイートで execute を呼び出します。

scala> import org.scalatest._
import org.scalatest._

scala> class NumSuite(num: Int) extends Suite {
     |   override def suiteName = "NumSuite(" + num + ")"
     | }
defined class NumSuite

scala> val mySuites = for (i <- 1 to 5) yield new NumSuite(i)
mySuites: scala.collection.immutable.IndexedSeq[NumSuite] = Vector(NumSuite@3dc1902d,     NumSuite@6ee09a07, NumSuite@5ba07a6f, NumSuite@4c63c68, NumSuite@72a7d24a)

scala> stats.run(Suites(mySuites: _*))
Run starting. Expected test count is: 0
Suites:
NumSuite(1):
NumSuite(2):
NumSuite(3):
NumSuite(4):
NumSuite(5):
Run completed in 16 milliseconds.
Total number of tests run: 0
Suites: completed 6, aborted 0
Tests: succeeded 0, failed 0, ignored 0, pending 0
All tests passed.

出来上がり!

于 2012-02-29T21:52:03.077 に答える