Good in scala I just used FunSuite for unit tests along with the BeforeAndAfterAll attribute. Then you can simply run your sparkContext in beforeAll, output the HiveContext from it, and end it like this:
override def afterAll(): Unit = { if(sparkContext != null) sparkContext .stop() }
From what I noticed, it also closes the HiveContext attached to it.
source share