Thursday, 22 August 2013

Specs2 - close JDBC connection after each test case

Specs2 - close JDBC connection after each test case

I implemented specs2 specification that looks something like this:
class MySpec extends Specification {
"My database query" should {
"return some results " in {
val conn = createJdbcConn()
try {
// matcher here...
} finally {
conn.close()
}
}
}
This ugly boilerplate is repeated in all my test cases. I have to open
(and then close) a new connection for each in.
What is the idiomatic way in Specs2 close resources such as in this case -
perhaps using the After (or BeforeAfter) trait to properly close the
connection?

No comments:

Post a Comment