Hi,
I started to use specs2 seriously for my project, testing database. I had to update to "specs2-core" % "3.6.3" to get anything working, but that's another story.
Anyway, there are several scenarios in which I use some initial values, that are computed basing on several hard-drive files. The process takes 4-5 seconds, so if it was done once, it wouldn't be bad.
Unfortunately, there are several tests, where I really need to have the database clean (to see for instance if duplication elimination mechanisms work correctly). This gives me a multiplier, and my tests are getting 20 seconds longer pretty much everyday.
Is there a way to initialize database once, and then copy-and-paste it to other tests?
Right now I do:
trait WithSomeMatapDB extends BeforeAfterEach {
def admin = User.findUserByUniqueId(DefaultValues.getAdminUserId).get
override def before = {
DBHelper.initSquerylRecordWithInMemoryDB()
DBHelper.createSchema
DBHelper.putBasicTemplates
}
override def after = {
DBHelper.dropSchema
DBHelper.closeSession
}
}
where
def initSquerylRecordWithInMemoryDB() {
Class.forName("org.h2.Driver")
SquerylRecord.initWithSquerylSession {
val session = Session.create(DriverManager.getConnection("jdbc:h2:mem:testSquerylRecordDB;DB_CLOSE_DELAY=-1", "sa", ""), new H2Adapter)
// session.setLogger(statement => println(statement))
session
}
}
what I'd prefer to do is to read the h2database with some initial contents from hard drive (or even memory singleton), do a test, and reload it again to initial contents "BeforeAfterEach". It's "putBasicTemplates" that consumes several seconds, it communicates with outside services.
Any ideas?