我将使用akka-http
with Java
。路由成功完成并运行。但是当我尝试使用 编写测试用例时JUnitRouteTest
,出现错误。
com.james.controllers.PingPongApiTest is not abstract and does not override abstract method yeOldeTestNames() in org.scalatest.Suite
我正在关注akka http route testkit 文档。根据这个文档,我们只需要akka-http-testkit
. 但是对于Java
我们也需要Junit
依赖。只有junit依赖我得到另一个错误是cannot access org.scalatest.junit.JUnitSuiteLike
。我也注入了 scala 测试依赖,如下所示:
libraryDependencies ++= Seq(
"com.typesafe.akka" % "akka-http-experimental_2.11" % "2.4.8",
"com.typesafe.akka" % "akka-http-testkit_2.11" % "2.4.8" % "test",
"junit" % "junit" % "4.12" % "test",
"org.scalatest" % "scalatest_2.11" % "3.0.0" % "test"
)
然后我收到以下错误:
com.james.controllers.PingPongApiTest is not abstract and does not override abstract method yeOldeTestNames() in org.scalatest.Suite
[error] public class PingPongApiTest extends JUnitRouteTest {
[error] TestRoute route = testRoute(new PingPongApi().handleGetPingRequest());
[error]
[error] @Test
[error] public void testGetPingRequest() {
[error]
[error] route.run(HttpRequest.GET("/ping"))
[error] .assertStatusCode(StatusCodes.OK)
[error] .assertEntity("pong");
[error] }
[error] }
[error] (test:compileIncremental) javac returned nonzero exit code
[error] Total time: 1 s, completed 10 Aug, 2016 11:28:11 AM
我怎么能解决这个问题。以下是我的代码:
路线类
public class PingPongApi {
public Route handleGetPingRequest() {
return get(() -> route(
path("ping", () -> complete("pong"))
));
}
}
测试班
public class PingPongApiTest extends JUnitRouteTest {
TestRoute route = testRoute(new PingPongApi().handleGetPingRequest());
@Test
public void testGetPingRequest() {
route.run(HttpRequest.GET("/ping"))
.assertStatusCode(StatusCodes.OK)
.assertEntity("pong");
}
}