假设我有一个库,其中包含已弃用的函数和首选函数:
object MyLib {
def preferredFunction() = ()
@deprecated("Use preferredFunction instead", "1.0") def deprecatedFunction() = ()
}
我想测试两者preferredFunction
and deprecatedFunction
在 Scala 测试中:
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()
^
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)