很难说究竟有哪些问题是不知道你是哪个斯卡拉, SBT,Scalatest等版本使用,但这可以使用更新的版本。 与其试图准确确定与旧版本的断开连接的位置,我认为在当前版本中您可以更轻松一些。
build.sbt:
resolvers ++= Seq(
"Sonatype releases" at "https://oss.sonatype.org/content/repositories/releases"
)
libraryDependencies += "org.scalactic" %% "scalactic" % "2.2.6"
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.6" % "test"
测试类:
import org.scalatest.FunSuite
// Random implementation because I'm not sure what Martin's elem class is.
case class elem(someField: Char, width: Int, height: Int)
class ElemSuite extends FunSuite {
test("D") {
val ele = elem('x', 2, 3)
assert(ele.width === 2)
}
}
我觉得这是你会得到书中的代码最接近的匹配。不过,我喜欢使用FlatSpec和FeatureSpec与匹配器写我的测试时沿:
import org.scalatest.{FlatSpec, Matchers}
class ElemSpec extends FlatSpec with Matchers
{
it should "retrieve the correct width" in {
val ele = elem('x', 2, 3)
ele.width shouldBe 2
}
}
不过,如果你是新来斯卡拉,你可能会坚持的风格, 书相匹配的更好。
上ScalaTest风格的更多信息:http://www.scalatest.org/user_guide/selecting_a_style
免责声明:我其实是采用了最新的3.0.0发布候选,但我 认为这些简单的测试仍然会使用你的2.2.6工作。
不知道,但我不认为JUnit3Suite被广泛使用,自从Odersky写他的书以来,Scalatest已经经历了几个版本。我一直使用Funsuite - 请试试? –