Scala 未找到:值assertThrows
我有以下测试课程:Scala 未找到:值assertThrows,scala,scalatest,Scala,Scalatest,我有以下测试课程: import org.scalatest.FunSuite @RunWith(classOf[JUnitRunner]) class NodeScalaSuite extends FunSuite { 采用本试验方法: test("Now doesn't terminate future that's not done") { val testFuture: Future[Int] = Future{ wait(1000) 10
import org.scalatest.FunSuite
@RunWith(classOf[JUnitRunner])
class NodeScalaSuite extends FunSuite {
采用本试验方法:
test("Now doesn't terminate future that's not done") {
val testFuture: Future[Int] = Future{
wait(1000)
10
}
assertThrows[NoSuchElementException]{
testFuture.now
}
}
我得到这个错误:
not found: value assertThrows
我在这里查看了ScalaTest文档,与我类似的代码似乎工作正常
问题出在哪里?我也遇到了这个问题,但正如评论中提到的,这取决于我使用的scala测试版本
assertThrows
是在2.2.6之后才引入的-升级到3.0.0(如果可以)将使之成为可能:请参见此处引用文档的旧版本:
如果无法升级,则先前断言异常的方法是使用截取方法:
test("Invoking head on an empty Set should produce NoSuchElementException") {
intercept[NoSuchElementException] {
Set.empty.head
}
}
你用的是什么版本?我在2.2.6
中遇到了同样的问题(用于ScalaMock兼容性)。