What is the right way to use ScalaTest's BeforeAndAfterAll trait with sbt and IntelliJ IDEA?
<p>I'm attempting to set up a testing framework for Spark jobs. I'd like to use <a href="https://github.com/holdenk/spark-testing-base" rel="nofollow noreferrer">spark-testing-base</a>'s SharedSparkContext trait which relies on ScalaTest's BeforeAndAfterAll trait to manage setup and tear-down. Something about my current environment is causing the beforeAll and afterAll methods to be called around each test case. </p>

<p>(Even if I wanted to permit this redundant behavior, I couldn't: I don't know how to tear down my HiveContext object properly, so the second call to beforeAll throws an exception that bottoms out at "ERROR XSDB6: Another instance of Derby may have already booted the database /Users/applemacbookpro/git/my-project/metastore_db.")</p>

<p>I'm using IntelliJ IDEA with an SBT-managed build.</p>

<ul>
<li>MacOS 10.11.4</li>
<li>IntelliJ IDEA 2016.1.3</li>
<li>not sure about SBT version, should be recent</li>
<li>ScalaTest 2.2.6</li>
</ul>

<p>Per the README of spark-testing-base and <a href="https://stackoverflow.com/questions/33237856/how-to-correctly-use-spark-in-scalatest-tests">this question</a>, I've put</p>

<pre><code>parallelExecution in Test := false 
</code></pre>

<p>in build.sbt.</p>

<p>Here's my example:</p>

<pre><code>import org.scalatest.{BeforeAndAfterAll, FlatSpec}

class ExampleSpec extends FlatSpec with BeforeAndAfterAll {
  override def beforeAll(): Unit = {
    println("in beforeAll")
    super.beforeAll()
  }

  override def afterAll() {
    println("in afterAll")
    super.afterAll()
  }

  behavior of "example"

  it should "succeed" in {
    println("test 1")
  }

  it should "succeed again" in {
    println("test2")
  }
}
</code></pre>

<p>I trigger it by right-clicking in the editor window and running from the context menu; the output is:</p>

<pre><code>/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/bin/java...
Testing started at 2:50 PM ...
in beforeAll
test 1
in afterAll
in beforeAll
test2
in afterAll

Process finished with exit code 0
</code></pre>