scala - 测试已弃用的 Scala 函数时如何抑制弃用警告?

标签 scala unit-testing testing deprecated scalatest

假设我有一个库,其中包含一个已弃用的函数和一个首选函数:

object MyLib {
  def preferredFunction() = ()
  @deprecated("Use preferredFunction instead", "1.0") def deprecatedFunction() = ()
}

我想在 ScalaTest 中同时测试 preferredFunctiondeprecatedFunction:

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/

相关文章:

database-design - 实现大型系统更改

unit-testing - Espresso - withEffectiveVisibility 与 isDisplayed

scala - 如何将递归函数转换为尾递归版本?

php - 单元测试套接字

ruby-on-rails - 在集成测试中访问 session

ios - 我怎样才能取消-[UIScrollView zoomToRect :animated:]?

unit-testing - Java EE 6 中的嵌入式容器与托管容器有什么区别?

scala - < :< operator in scala

scala - 如何在 Scala 中使用滑动流获取斐波那契数列?

scala - 如何编译Scala Hello World应用程序