0

で使用する予定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");
 }
}
4

1 に答える 1

1

上記の問題の解決策を見つけました。依存バージョンの主な問題。Java ルーティング テスト ケースを実行するには、依存関係が必要でしscalatestた。以下は、必要な依存関係です。JUnitRouteTestscalatest

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",
 "org.scalatest" %% "scalatest" % "2.2.4" % "test",
 "junit" % "junit" % "4.12" % "test",
 "com.novocode" % "junit-interface" % "0.11" % "test" exclude("junit", "junit")
)
于 2016-08-11T12:04:38.240 に答える