2

我在 OS X 上使用 Play Framework v2.04 和 Scala(通过 Homebrew 安装)。一切都按预期工作,但是我似乎无法从 Play 网站的文档中运行基本的Hello World示例 specs2 测试。这是我/app/test/example.scala文件中的代码:

import org.specs2.mutable._

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

class HelloWorldSpec extends Specification {

  "The 'Hello world' string" should {
    "contain 11 characters" in {
      "Hello world" must have size(11)
    }
    "start with 'Hello'" in {
      "Hello world" must startWith("Hello")
    }
    "end with 'world'" in {
      "Hello world" must endWith("world")
    }
  }
}

但是,当我运行时play test,出现以下错误:

[error] /app/test/example.scala:3: object test is not a member of package play.api

AFAIK,测试对象应该是 play.api 包的成员(根据 API 参考文档)。

关于如何解决这个问题的任何想法?

谢谢!

4

2 回答 2

6

在项目根目录下创建test目录并将example.scalafrom移动app/testtest.

于 2013-01-10T14:18:52.040 回答
0

在 IntelliJ IDEA 中“将目录标记为”>“测试源根目录”。在项目窗口中单击鼠标右键。

IDEA 可能会被不规范的项目布局所误导。通常测试库是依赖类型“test”,当不被识别为“test”代码时不会编译。

于 2017-05-30T20:47:03.957 回答