Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 未找到:值assertThrows_Scala_Scalatest - Fatal编程技术网

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兼容性)。