Search code examples
scalajunitscalatest

ScalaTest - JUnitRunner cannot be found


I am trying to run my tests with the annoatqaion as per ScalaTest website:

import org.scalatest.FunSuite
import org.hamcrest.Matchers._
import org.hamcrest.MatcherAssert._
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import scala.Predef.String


@RunWith(classOf[JUnitRunner])

I am getting the following error messages when I try to build:

    error: not found: object classOf
@RunWith(classOf[JUnitRunner])

error: annotation argument needs to be a constant; found: <error: <none>>[JUnitRunner]
@RunWith(classOf[JUnitRunner])

If I remove the annotation the tests run as well, but I presume the point of the annotation is to allow better running environment from JUnit... ANy help would be greatly appreaciated


Solution

  • Remove this import to make it work:

    import scala.Predef.String
    

    All members of Predef are automatically imported for you by the compiler, unless you import a selective one manually like this. classOf is a member of Predef and gets hidden this way.