Implementing Junit @BeforeAll like behaviour in scalatest

157 views Asked by At

I am using scalatest to write unit tests in my application.I want to start embedded elastic server before starting my test suites and tear it down once all the test suite complete. Scalatest provides BeforeAndAfterAll and BeforeAndAfter traits but they are applicable only for the tests in a single suite. How do I achieve this behaviour using scalatest.

1

There are 1 answers

3
Ivan Kurchenko On

In general, I'm not sure if it is possible to run some code before entire test suite execution, maybe on sbt configuration level. But for the case you descibed

I want to start embedded elastic server

You can take a look at TestContainers project and it's Scala integration - essentially this is the case for which this library was designed - to setup external environment for tests before start. And it has elasticsearch support out of the box.

Hope this helps!