简体   繁体   English

Play框架和Scala导入

[英]Play Framework and Scala import

I've installed Play Framework 2.5 by downloading and extracting the Activator bundle version. 我已经通过下载并提取Activator捆绑软件版本安装了Play Framework 2.5。 I used the activator command to create a new Play scala application and then entered the play console. 我使用了activator命令创建了一个新的Play scala应用程序,然后进入了Play控制台。 Inside the play console I typed console to get the scala repl. 在播放控制台中,我键入了console以获取scala副本。 At the prompt I tried to import WithApplication from the play.api.test package and got the following error 在提示符下,我尝试从play.api.test包中导入WithApplication并收到以下错误

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. 我还尝试将其导入到ExampleControllerSpec.scala中的测试目录内创建的测试类内,并得到相同的错误。

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 这是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 如果我看一下文档,就会发现它在那里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 ? 那么,为什么它在我的测试班和scala repl中不起作用?

Use test:console in the REPL. 在REPL中使用test:console Test classes are not all loaded into the main compilation scope. 测试类未全部加载到主编译范围中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM