Execute the following code
https://doc.akka.io/docs/akka-http/current/routing-dsl/testkit.html ...
java.lang.NoClassDefFoundError: akka / testkit / package $ TestDuration $
It depends on akka-testkit. Is it behaving correctly?
Unfortunately your link just points to the 'Route TestKit' page, which code from that page are you using? Are you using Java or Scala? For Scala, Are you using scalatest or specs2? Could you share the complete stack trace you're seeing?
That said, yes, akka-http-testkit indeed depends on akka-stream-testkit which in turn depends on akka-testkit.
Normally, if you are using a build system (such as Maven, sbt, etc), this should be automatically pulled in because this dependency is declared in the pom.xml, but I see in this case the dependency is declared as 'provided'. This was likely done because this makes the choice of Akka version an explicit one.
At https://doc.akka.io/docs/akka-http/current/introduction.html#using-akka-http we show both the akka-http and the akka-stream dependency. It would indeed be an improvement to do the same at https://doc.akka.io/docs/akka-http/current/routing-dsl/testkit.html and show both akka-http-testkit and akka-stream-testkit here.
Would you be interested in providing a PR adding this to the documentation?
I am using scala.
It is scalatest.
A needed class was not found. This could be due to an error in your runpath. Missing class: akka/testkit/package$TestDuration$
java.lang.NoClassDefFoundError: akka/testkit/package$TestDuration$
at akka.http.scaladsl.testkit.RouteTestTimeout$.default(RouteTestTimeout.scala:14)
at example.restapi.FullTestKitExampleSpec.$anonfun$new$2(FullTestKitExampleSpec.scala:26)
at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at org.scalatest.WordSpecLike$$anon$1.apply(WordSpecLike.scala:1078)
at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
at org.scalatest.WordSpec.withFixture(WordSpec.scala:1881)
at org.scalatest.WordSpecLike.invokeWithFixture$1(WordSpecLike.scala:1076)
at org.scalatest.WordSpecLike.$anonfun$runTest$1(WordSpecLike.scala:1088)
at org.scalatest.SuperEngine.runTestImpl(Engine.scala:289)
at org.scalatest.WordSpecLike.runTest(WordSpecLike.scala:1088)
at org.scalatest.WordSpecLike.runTest$(WordSpecLike.scala:1070)
at org.scalatest.WordSpec.runTest(WordSpec.scala:1881)
at org.scalatest.WordSpecLike.$anonfun$runTests$1(WordSpecLike.scala:1147)
at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:396)
at scala.collection.immutable.List.foreach(List.scala:392)
at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:384)
at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:373)
at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:410)
at scala.collection.immutable.List.foreach(List.scala:392)
at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:384)
at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:379)
at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:461)
at org.scalatest.WordSpecLike.runTests(WordSpecLike.scala:1147)
at org.scalatest.WordSpecLike.runTests$(WordSpecLike.scala:1146)
at org.scalatest.WordSpec.runTests(WordSpec.scala:1881)
at org.scalatest.Suite.run(Suite.scala:1147)
at org.scalatest.Suite.run$(Suite.scala:1129)
at org.scalatest.WordSpec.org$scalatest$WordSpecLike$$super$run(WordSpec.scala:1881)
at org.scalatest.WordSpecLike.$anonfun$run$1(WordSpecLike.scala:1192)
at org.scalatest.SuperEngine.runImpl(Engine.scala:521)
at org.scalatest.WordSpecLike.run(WordSpecLike.scala:1192)
at org.scalatest.WordSpecLike.run$(WordSpecLike.scala:1190)
at example.restapi.FullTestKitExampleSpec.org$scalatest$BeforeAndAfterAll$$super$run(FullTestKitExampleSpec.scala:8)
at org.scalatest.BeforeAndAfterAll.liftedTree1$1(BeforeAndAfterAll.scala:213)
at org.scalatest.BeforeAndAfterAll.run(BeforeAndAfterAll.scala:210)
at org.scalatest.BeforeAndAfterAll.run$(BeforeAndAfterAll.scala:208)
at example.restapi.FullTestKitExampleSpec.run(FullTestKitExampleSpec.scala:8)
at org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:45)
at org.scalatest.tools.Runner$.$anonfun$doRunRunRunDaDoRunRun$13(Runner.scala:1346)
at org.scalatest.tools.Runner$.$anonfun$doRunRunRunDaDoRunRun$13$adapted(Runner.scala:1340)
at scala.collection.immutable.List.foreach(List.scala:392)
at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:1340)
at org.scalatest.tools.Runner$.$anonfun$runOptionallyWithPassFailReporter$24(Runner.scala:1031)
at org.scalatest.tools.Runner$.$anonfun$runOptionallyWithPassFailReporter$24$adapted(Runner.scala:1010)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1506)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1010)
at org.scalatest.tools.Runner$.run(Runner.scala:850)
at org.scalatest.tools.Runner.run(Runner.scala)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:131)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:28)
Caused by: java.lang.ClassNotFoundException: akka.testkit.package$TestDuration$
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 55 more
add libraryDependencies
"com.typesafe.akka" %% "akka-testkit" % "2.5.21" % Test
This solved it.
I understood that it depends.
There is no problem adding to the document.
Thank you
(this was already improved in the documentation, that improved version of the page will be released as part of version 10.1.8 #2389)
Most helpful comment
add libraryDependencies
"com.typesafe.akka" %% "akka-testkit" % "2.5.21" % Test
This solved it.
I understood that it depends.
There is no problem adding to the document.
Thank you