Reputation: 2089
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 ?
Upvotes: 0
Views: 843
Reputation: 6172
Use test:console
in the REPL. Test classes are not all loaded into the main compilation scope.
Upvotes: 2