title: Unit testing in Spark with SQLContext implicits
body: <p>I'm trying to run multiple unit tests in Spark and have copied (and slightly adapted) the bit from the source code:</p>
  
  <pre><code>import org.apache.spark.sql.SQLContext
  import org.apache.spark.{SparkConf, SparkContext}
  import org.scalatest.{BeforeAndAfterAll, Suite}
  
  trait SharedSparkContext extends BeforeAndAfterAll {
    self: Suite =&gt;
  
    @transient private var _sc: SparkContext = _
    @transient private var _sqlContext: SQLContext = _
  
    def sc: SparkContext = _sc
    def sqlContext: SQLContext = _sqlContext
  
    private var conf = new SparkConf(false)
  
    override def beforeAll() {
      super.beforeAll()
      _sc = new SparkContext("local[*]", "Test Suites", conf)
      _sqlContext = new SQLContext(_sc)
    }
  
    override def afterAll() {
      try {
        LocalSparkContext.stop(_sc)
        _sc = null
      } finally {
        super.afterAll()
      }
    }
  }
  </code></pre>
  
  <p>The LocalSparkContext class with companion object are simply copied from the source.</p>
  
  <p>I thought about using it as follows, which tells me that <code>stable identifier required</code> because the <code>def</code> <code>sqlContext</code> does not have the member <code>implicits</code>:</p>
  
  <pre><code>class MySuite extends FlatSpec with SharedSparkContext {
    import sqlContext.implicits._
    // ...
  }
  </code></pre>
  
  <p>I have tried replacing it with the following, but that gives me null pointer exceptions:</p>
  
  <pre><code>class MySuite extends FlatSpec with SharedSparkContext {
    val sqlCtxt = sqlContext
    import sqlCtxt.implicits._
    // ...
  }
  </code></pre>
  
  <p>I am using Spark 1.4.1 and I have set <code>parallelExecution in test := false</code>.</p>
  
  <p>How can get this to work (without using additional packages)?</p>