2

Getting started with "Testing Akka Actors"

I think there is something wrong with my "akka-testkit" library-dependency. I copied it from Lightbend Testing Classic Actors

build.sbt

version := "0.1.0-SNAPSHOT"

scalaVersion := "2.12.7"

val akkaVersion = "2.5.13"

libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor" % akkaVersion,
  "org.scalatest" %% "scalatest" % "3.0.5",
  "com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test
)

.scala

package part3testing

import akka.actor.ActorSystem
import akka.testkit.TestKit

class BasicSpec extends TestKit(ActorSystem("BasicSpec")){

}

1 Answers1

3

Marking a dependency as % Test means that only code in the test directories (by default, src/test) will depend on it. Main application code (by default in src/main) does not depend on test-scope dependencies; the benefit of this is that the test dependencies aren't needed for distributing/deploying the built software so don't get included or need to be provided.

Levi Ramsey
  • 18,884
  • 1
  • 16
  • 30
  • I removed `%Test` from `"com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test` , did refresh and it works. Thanks – Always_a_learner Oct 04 '22 at 10:49
  • 1
    @Always_A_Learner you should probably not use test dependencies in main code, unless you are writing a tests library maybe? – Gaël J Oct 04 '22 at 15:32