で使用する予定akka-http
ですJava
。ルーティングが正常に実行されました。しかし、を使用してテストケースを作成しようとするとJUnitRouteTest
、エラーが発生しました。
com.james.controllers.PingPongApiTest is not abstract and does not override abstract method yeOldeTestNames() in org.scalatest.Suite
akka http route testkit documentationに従っています。このドキュメントによると、必要なのは のみでし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");
}
}