1

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.

Sumit Nekar
  • 175
  • 13
  • Does this answer your question? [Doing something before or after all Scalatest tests](https://stackoverflow.com/questions/15423337/doing-something-before-or-after-all-scalatest-tests) – stefanobaghino Feb 20 '20 at 12:46
  • Well sort of. But there are some caveats with the approaches mentioned in this thread. Looking for a better solution. – Sumit Nekar Feb 20 '20 at 12:51

1 Answers1

0

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!

Ivan Kurchenko
  • 4,043
  • 1
  • 11
  • 28
  • Thanks @Ivan Kurchenko. I looked at this. I have a problem here. Docker container is starting for every spec I write. For example I have two specs TestSpec1 and TestSpec2 two separate classes. I want to start only one container instance before all tests run.Any thoughts on achieving this. – Sumit Nekar Apr 21 '20 at 10:54
  • @SumitNekar According to documentation you need to use `ForAllTestContainer` as a base for your specs, so environment will be created for all your suites. – Ivan Kurchenko Apr 21 '20 at 11:01
  • 1
    This trait starts one instance per one spec file .ie one instance for all all the tests in one spec file. My requirement is to start one instance before multiple spec files. – Sumit Nekar Apr 21 '20 at 13:05