0

I am going to use akka-http with Java. The routing done successfully and run. But when i trying to write test case using JUnitRouteTest, i got an error.

com.james.controllers.PingPongApiTest is not abstract and does not override abstract method yeOldeTestNames() in org.scalatest.Suite

I am following akka http route testkit documentation. According to this documentation, we required only akka-http-testkit. But for Java We also required Junit depedency. With only junit dependency i got another error is cannot access org.scalatest.junit.JUnitSuiteLike. I am also inject scala test depedency as below:

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"
) 

Then i got the below error:

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

How could i resolve the problem. Following is my code:

Route Class

public class PingPongApi  {

 public Route handleGetPingRequest() {
    return get(() -> route(
            path("ping", () -> complete("pong"))
    ));
 } 
}

Test Class

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");
 }
}
Harmeet Singh Taara
  • 6,483
  • 20
  • 73
  • 126

1 Answers1

1

I found the solution for above problem. The main problem with our dependencies versions. For running Java Routing test cases, we required scalatest dependency, because JUnitRouteTest using scalatest. Following are the dependencies we required.

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")
)
Harmeet Singh Taara
  • 6,483
  • 20
  • 73
  • 126