2

質問を更新し、読みやすくするために古いテキストを削除しました。

scalaVersion  := "2.10.1"
"org.specs2"          %%  "specs2"        % "1.13" % "test"

私のspec2テスト:

package com.mycompany.dataminer.parser

import org.specs2.mutable.Specification

case class Product(productID:String)

class SimpleTest  extends Specification {

  "product" should {

    "have id = 123" in {
      var product1 = Product("123")
      product1 must not beNull
      product1.productID must_== "123"

      var product2 = Product("123")
      product2 must not beNull
      product2.productID must_== "123"

      var product3 = Product("123")
      product3 must not beNull
      product3.productID must_== "123"
    }
  }

}

結果:

scala: type mismatch;
 found   : String
 required: org.specs2.matcher.Matcher[com.mycompany.dataminer.parser.Product]
      product1.productID must_== "123"
               ^

このコードを書いたら、次の行を追加するまでは機能していました。

product1 must not beNull
product2 must not beNull
product3 must not beNull
4

2 に答える 2

1

私の推測:

  1. インポート名の競合、または
  2. 仕様に何か問題がある

おそらく、次の受け入れテストの例が手がかりになるでしょう。

import org.specs2.Specification
 import xyz.{Product => TestProduct} // <- "Product" パッケージのエイリアス

特性 MyTestHelper { val pId = "123" lazy val product = new TestProduct.Product(pId, ...) // <-- テストするクラス }

class MyTest は仕様を MyTestHelper で拡張します { def is = ("商品は" + pId) ! product.ProductID は_==("123") ^ である必要があります 終わり }

于 2013-04-28T16:47:45.967 に答える