We have an issue with different environments for our integration tests and start/stop latency.
So, we want to run all environment dependencies before all integration tests and shut down after all. We can't just use docker since we use GuiceApplication (starts from the code), EmbeddedKafka (starts from the code), and WireMock(starts from the code). :)
We use scala as a main language and Specs2 as testing library. I've found that we can create one spec, add before/after all code to set up env, and override the is method, which represents the test. We can join a few other Specs into one by
override def is = Seq(new First, new Second)
.map(_.is)
.foldLeft(Fragments.empty) { case (l, r) => l.append(r.fragments)}
But I want to automatically gather specs into is. I see a SpecificationFinder trait with methods such as findSpecifications and specifications, but I can't make them return a non-empty list. We have a root directory called 'integrations,' where we store all needed Specs.
Maybe someone has already implemented the search over tests. It looks like these methods are used during the sbt test task, but I didn't find a way to reuse it as I want
There are two answers to that questions depending on the specs2 version that you are using.
specs2-4.x (full example here)
With this version you can collect specifications using a
SpecificationsFinderand aggregate them as one big specification with onestepbefore and onestepafter to start and stop shared services:specs2-5.x (full example here)
With more recent version of specs2 a notion of "global resource" has been introduced so that each individual specification can extend a
Resource[R]trait (whereRis a global resource, here is an example with aDatabase):and in that case the
stepsused in the previousIntegrationSpecare not necessary anymore.