title: Why are implicit variables not initialized in Scala when called from unit test?
body: <p>Given the the following singleton Object in Scala:</p>
  
  <pre><code>package demo
  
  import akka.actor.ActorSystem
  import akka.http.scaladsl.Http
  import akka.http.scaladsl.server.Directives._
  import akka.stream.ActorMaterializer
  
  import scala.concurrent.Future
  import scala.io.StdIn
  
  object WebServer extends App {
  
    implicit val system = ActorSystem("myActorSystem")
    implicit val executionContext = system.dispatcher
    implicit val materializer = ActorMaterializer()
  
    val route = {
      path("api" / "done-as-promised") {
        get {
          complete {
            Future.successful("done")
          }
        }
      }
    }
  
    val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)
  
  }
  </code></pre>
  
  <p>And the following unit test</p>
  
  <pre><code>package demo
  
  import akka.http.scaladsl.testkit.ScalatestRouteTest
  import org.scalactic.TypeCheckedTripleEquals
  import org.scalatest.{Inspectors, Matchers, WordSpec}
  
  class WebServerSpec extends WordSpec with Matchers with TypeCheckedTripleEquals with Inspectors with ScalatestRouteTest {
  
    "The WebServer /done-as-promised" should {
      "return done" in {
        // tests:
        Get("/api/done-as-promised") ~&gt; WebServer.route ~&gt; check {
          status.intValue() shouldEqual 200
          responseAs[String] shouldEqual "done"
        }
      }
    }
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>[ERROR] [04/19/2016 07:12:18.995]
    [ScalaTest-run-running-WebServerSpec]
    [akka.actor.ActorSystemImpl(demo-WebServerSpec)] Error during
    processing of request
    HttpRequest(HttpMethod(GET),<a href="http://example.com/api/done-as-promised,List(),HttpEntity.Strict(none/none,ByteString()),HttpProtocol(HTTP/1.1)" rel="nofollow">http://example.com/api/done-as-promised,List(),HttpEntity.Strict(none/none,ByteString()),HttpProtocol(HTTP/1.1)</a>)
    java.lang.NullPointerException    at
    akka.http.scaladsl.server.directives.ExecutionDirectives$$anonfun$handleExceptions$1$$anonfun$apply$1.apply(ExecutionDirectives.scala:33)
      at
    akka.http.scaladsl.server.directives.ExecutionDirectives$$anonfun$handleExceptions$1$$anonfun$apply$1.apply(ExecutionDirectives.scala:29)
      at
    akka.http.scaladsl.testkit.RouteTest$TildeArrow$$anon$1.apply(RouteTest.scala:162)
      at
    akka.http.scaladsl.testkit.RouteTest$TildeArrow$$anon$1.apply(RouteTest.scala:150)</p>
  </blockquote>