Search code examples
scalaunit-testingtestingdeprecatedscalatest

How to suppress deprecation warnings when testing deprecated Scala functions?


Suppose I have a library, which contains both a deprecated function and a preferred function:

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

I want to test both preferredFunction and deprecatedFunction in ScalaTest:

class MyLibSpec extends FreeSpec with Matchers {
  "preferred function" in {
    MyLib.preferredFunction() should be(())
  }
  "deprecated function" in {
    MyLib.deprecatedFunction() should be(())
  }
}

However, a deprecation warning is reported at MyLib.deprecatedFunction().

How to avoid the warning?


Solution

  • Scala does not support that, see https://groups.google.com/forum/#!topic/scala-internals/LsycMcEkXiA

    However there is a plugin mentioned:

    https://github.com/ghik/silencer

    I haven't used it - so I am not sure if this works for your case.