elastic4s icon indicating copy to clipboard operation
elastic4s copied to clipboard

Use testcontainers-scala in tests to launch Elasticsearch instance

Open igor-vovk opened this issue 7 months ago • 2 comments

If I understood correctly, running tests locally now requires manually launching elasticsearch instance. Also it is done this way in GitHub Actions build script. This can be improved by using https://github.com/testcontainers/testcontainers-scala that will start elasticsearch container automatically when tests are running.

Article with explanation of the approach: https://www.baeldung.com/scala/testcontainers-scala.

Pros:

  • Fresh instance of Elastic for each test suite, so the leftovers from other suites (for example, the data that was created and not cleaned up) won't intervene
  • No need to configure the env to run tests, just running sbt test will start needed containers

Cons:

  • Instance is started per test suite, which may take too long to start

igor-vovk avatar Jul 18 '24 05:07 igor-vovk