gpt4 book ai didi

scala - 未找到 : value assertThrows

转载 作者:行者123 更新时间:2023-12-04 00:41:21 24 4
gpt4 key购买 nike

我有以下测试类:

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 文档 http://doc.scalatest.org/3.0.0/#org.scalatest.FunSuite和我的类似的代码似乎工作正常。

有什么问题?

最佳答案

我也刚遇到这个问题 - 但正如评论中提到的,这取决于我使用的 scala 测试版本。 assertThrows直到 2.2.6 之后才引入 - 升级到 3.0.0(如果可以)将使其成为可能:请参阅此处引用文档的旧版本:http://doc.scalatest.org/2.2.6/#org.scalatest.FunSuite

如果你不能升级,之前断言异常的方法是使用 intercept方法:

  test("Invoking head on an empty Set should produce NoSuchElementException") {
intercept[NoSuchElementException] {
Set.empty.head
}
}

关于scala - 未找到 : value assertThrows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39194331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com