Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT/Scala and Integration testing

Tags:

While researching on the subject of automating my integration tests, I found out a nice plugin in the maven world called FailSafe. it gives me phases like pre-integration-test, post-integration-test and integration-test.

By tying into these phases, I can have other plugins which can start/stop and run docker images.

The plugin also has a nice way in which I can differentiate between UnitTests and IntegrationTests (even though both are written in JUNIT).

Well now the question is how can I do the same thing with Scala / SBT combination?

my requirement is

  1. Write Integration tests in SpecFlow.
  2. Integration tests are treated differently than unit tests.
  3. First Unit Tests are run.
  4. Then docker containers are created and run
  5. then integration tests are run.
  6. docker contains are shut-down.
  7. test results are captured in files. (just like surefire/failsafe plugins).

Is this possible in Scala/sbt combo?

like image 832
Knows Not Much Avatar asked Apr 14 '16 18:04

Knows Not Much


People also ask

What is sbt testing?

The serum bactericidal test (SBT) has been used for almost 40 years to monitor therapy in patients with bacterial endocarditis, osteomyelitis, and other serious infections.

Does sbt run tests in parallel?

By default, sbt executes tasks in parallel (subject to the ordering constraints already described) in an effort to utilize all available processors. Also by default, each test class is mapped to its own task to enable executing tests in parallel.

Does sbt test compile?

We have a build. sbt file that is used for multiple projects. Doing sbt test:compile compiled the tests for every single project and took over 30 minutes.


2 Answers

A simple solution is to run $ sbt "~ it:test" (make sure integration test are in a package named 'it') for integration test which will automatically run every time source code is updated. Furthermore, $sbt "~ test" for automated unit testing. If you are using a IDE such as IntelliJ IDEA, you can make it easier to run this in a custom configuration from the IDE. Hope this helps a little bit. I run these all the time when working.

like image 187
ZDevelop94 Avatar answered Sep 27 '22 17:09

ZDevelop94


I found the answer to the question. SBT provides means to do integration test and also setup and cleanup methods to do things like creation / destruction of docker containers

http://www.scala-sbt.org/0.13/docs/Testing.html

like image 36
Knows Not Much Avatar answered Sep 27 '22 16:09

Knows Not Much