0
votes

I've installed Play Framework 2.5 by downloading and extracting the Activator bundle version. I used the activator command to create a new Play scala application and then entered the play console. Inside the play console I typed console to get the scala repl. At the prompt I tried to import WithApplication from the play.api.test package and got the following error

scala> import play.api.test.{WithApplication}
<console>:10: error: object WithApplication is not a member of package play.api.test
       import play.api.test.{WithApplication}

I also tried to import it inside a test class created inside the test directory in ExampleControllerSpec.scala and got the same error.

import org.scalatest._
import org.scalatestplus.play._

import play.api.mvc._
import play.api.test._
import play.api.test.Helpers._

class ExampleControllerSpec extends PlaySpec {
  "Example Page#index" should {
    "should be valid" in new WithApplication {
    }
  }
}

Here is the output from the PlayConsole

$ test
[info] Compiling 1 Scala source to D:\Play\TestApp\target\scala-2.11\test-classes...
[error] D:\Play\TestApp\test\ExampleControllerSpec.scala:10: not found: type WithApplication
[error]     "should be valid" in new WithApplication {
[error]                              ^
[error] one error found
[error] (test:compileIncremental) Compilation failed

If I look at the documentation I see that it is there https://www.playframework.com/documentation/2.5.x/api/scala/index.html#play.api.test.package

So why it doesn't work in my test class and in the scala repl ?

1
When made the import in the test file, what activator command did you run that triggered the error?Alvaro Carrasco
I run the test command for testing the file.jerome
Even in Play 2.4 I only have WithApplication available in play.test, not play.api.test. So if you need a quick fix use that import, however it's really strange that it's not in play.api.test since the docs say it should be. Play has very confusing documentation, I've been searching for the past 20 mins and I can't really figure it out. It should be there but it isn't.slouc
Running the test command works fine for me with the import line on a test file in the test directory. Can you post the full test file, the exact location of it, and the full command you are running?Alvaro Carrasco
I'm exactly like @slouc said, it works using WithApplication from play.test and not from play.api.test. Is it normal ?jerome

1 Answers

2
votes

Use test:console in the REPL. Test classes are not all loaded into the main compilation scope.