title: Scala Akka Route Test - ActorRefFactory context must be defined
body: <p>Akka Http version: "10.0.11"</p>
  
  <p>I have the following route to test: </p>
  
  <pre><code>private def getAll: Route = pathPrefix("_all") {
    get {
      complete((todoRegistryActor ? GetAllTodos).mapTo[Todos].map(todosToTodoDtos))
    }
  }
  </code></pre>
  
  <p>And I have the following test: </p>
  
  <pre><code>class TodoRouteSpec extends WordSpec with Matchers
    with ScalatestRouteTest with RouteManager with BeforeAndAfterAll with TestKitBase with ImplicitSender {
  
    override implicit val system: ActorSystem = ActorSystem("TodoRouteSpec")
    override val executionContext: ExecutionContext = system.dispatcher
  
    private val todoRegistryProbe = TestProbe()
    override implicit val todoRegistryActor: ActorRef = todoRegistryProbe.ref
  
    override def afterAll {
      TestKit.shutdownActorSystem(system)
    }
  
    "The service" should {
      "return a list of todos for GET _all request" in {
        Get("/api/todo/_all").~&gt;(todoRoute)(TildeArrow.injectIntoRoute).~&gt;(check {
          //todoRegistryProbe.expectMsg(GetAllTodos)
  
          responseAs[TodosDto] shouldEqual TodosDto(Seq.empty)
          status should ===(StatusCodes.OK)
        })
      }
    }
  }
  </code></pre>
  
  <p>When running the following test, I receive the error: 
  <em>An exception or error caused a run to abort: ActorRefFactory context must be defined 
  java.lang.IllegalArgumentException: ActorRefFactory context must be defined</em></p>
  
  <ol>
  <li>I was looking what raised this error, but I can't find a solution.
  Does somebody know what raises this error?</li>
  <li>TildeArrow.injectIntoRoute has to be explicitly passed to get the test running. Found the solution here: <a href="https://stackoverflow.com/questions/28324230/how-can-i-fix-the-missing-implicit-value-for-parameter-ta-tildearrow-in-a-test">How can I fix the missing implicit value for parameter ta: TildeArrow in a test spec</a>. Maybe someone knows another solution?</li>
  </ol>
  
  <p>Thanks in advance</p>
  
  <p><strong>Solution</strong></p>
  
  <pre><code>class TodoRouteSpec extends WordSpec with Matchers with ScalatestRouteTest with TodoRoute {
  
    private lazy val routes = todoRoute
    private val todoRegistryProbe = TestProbe()
    todoRegistryProbe.setAutoPilot((sender: ActorRef, _: Any) =&gt; {
      sender ! Todos(Seq.empty)
      TestActor.KeepRunning
    })
    override implicit val todoRegistryActor: ActorRef = todoRegistryProbe.ref
  
    "TodoRoute" should {
      "return a list of todos for GET /todo/_all request" in {
        Get("/todo/_all").~&gt;(routes)(TildeArrow.injectIntoRoute).~&gt;(check {
          todoRegistryProbe.expectMsg(GetAllTodos)
  
          status should ===(StatusCodes.OK)
          contentType should ===(ContentTypes.`application/json`)
          entityAs[TodosDto] shouldEqual TodosDto(Seq.empty)
        })
      }
    }
  }
  </code></pre>