假设我有一个库,其中包含一个已弃用的函数和一个首选函数:
object MyLib {
def preferredFunction() = ()
@deprecated("Use preferredFunction instead", "1.0") def deprecatedFunction() = ()
}
我想在 ScalaTest 中同时测试 preferredFunction
和 deprecatedFunction
:
class MyLibSpec extends FreeSpec with Matchers {
"preferred function" in {
MyLib.preferredFunction() should be(())
}
"deprecated function" in {
MyLib.deprecatedFunction() should be(())
}
}
但是,在 MyLib.deprecatedFunction()
中报告了弃用警告。
如何避免警告?
最佳答案
只需弃用由测试装置反射实例化的类。
scala> @deprecated("","") def f() = ()
f: ()Unit
scala> @deprecated("","") class C { f() }
defined class C
scala> f()
<console>:13: warning: method f is deprecated:
f()
^
关于scala - 测试已弃用的 Scala 函数时如何抑制弃用警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52837691/