Hello World ScalaTest失败:未找到:键入MyScalatraServlet

时间:2014-06-06 07:14:22

标签: scala scalatra

我试图让Hello World在我的hello world scalatra应用程序中进行绿色测试。 servlet的代码是:

package com.graphular.app

import org.scalatra._
import scalate.ScalateSupport

class MyScalatraServlet extends GraphularStack {
  get("/") {
    <html>
      <body>
        <h1>Hello, world!</h1>
        Say <a href="hello-scalate">hello to Scalate</a>.
      </body>
    </html>
  }
}

它似乎可以在浏览器中使用,我对此非常满意。我为它编写了测试,并且如此:

import org.scalatra.test.scalatest._
import org.scalatest.FunSuite

class MyScalatraServletTests extends ScalatraSuite with FunSuite {
  addServlet(classOf[MyScalatraServlet], "/*")
  test("simple get") {
    get("/") {
      status should equal(200)
      body should include("hi!")
    }
  }
}

我的libraryDependencies是:

"org.scalatra" %% "scalatra" % ScalatraVersion,
"org.scalatra" %% "scalatra-scalate" % ScalatraVersion,
"org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
"ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime",
"org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container",
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar"))

我认为这会起作用,但我会继续接受:

[error] /Users/benmorgan/Sites/scala/graphular/src/test/scala/com/graphular/app/MyScalatraServletSpec.scala:7: not found: type MyScalatraServlet
[error]   addServlet(classOf[MyScalatraServlet], "/*")

我无法想象我的爱...

1 个答案:

答案 0 :(得分:1)

如果这是整个代码,那么你忘记了测试中的包语句:

package com.graphular.app

否则你应该导入被测试的课程。