I have some tests executing some sql queries on a table people
. I want to create this table only once, execute the tests, and then drop the table.
For the moment, the version I wrote does the creation and drop for each test. Here is my code:
def withTable(testCode: Unit => Any): Any = {
sparkSession.sql("CREATE TABLE people(id INT, name STRING, age BYTE) USING PARQUET")
try {
testCode
} finally {
sparkSession.sql("DROP TABLE people")
}
}
"global test" when {
"test1" should {
"do something" in withTable { _ =>
spark.sql(query1) shouldBe ...
}
}
"test2" should {
"do something" in withTable { _ =>
spark.sql(query2) shouldBe ...
}
}
}
How can I do the creation and drop only once ?