Running different test configurations for ScalaTest in IntelliJ 16.2

SBT allows specifying different *configurations* for running your tests: Test, IntegrationTest, etc.  

By default, the Test configuration looks for sources & resource files in src/test/scala & src/test/resources & the IntegrationTest in src/it/scala & src/it/resources, respectively.  When running SBT tasks such as `test`, they will run in the configuration's scope only: `it:test` will only run the integration tests & so on.

IntelliJ's default configuration for ScalaTest seems to be to run all tests in one package, which breaks the above contract if the package starts the same for all the tests (for us, it does).  That means, it also is not possible to set up IntegrationTest-specific run / debug configurations as they will be set up by package, not by folder structure as above.

Is it possible to set up IntelliJ, without changing the package structure, to only run ScalaTest in the directory instead?

Happy to provide more clarification if necessary.

5
5 comments

Unfortunately sbt's model can't be fully mapped to IDEA's project model, which results in some of the inconsistencies you are describing. We are working on a better sbt integration, which will allow delegating such tasks to sbt directly.

As a workaround, you can run sbt tasks from IDEA directly by creating an sbt run configuration (Run/Debug configurations, + icon, SBT task) that just calls it:test

2

How would one then incorporate Code Coverage if running tests as SBT tasks ?

0

The coverage execution is currently not supported, I've created an issue: https://youtrack.jetbrains.com/issue/SCL-14105

You may be able to add coverage support within the sbt configuration however.

 

0

It should be noted that resources don't merge so intellij cannot find the resources in `src/it/resources`.

0

Is there any update on this issue? As Ross mentioned, we are finding that resources in 'src/it/resources/' are not being picked up by default in IntelliJ. In a fresh checkout of our project, running our Scala integration tests from IntelliJ result in failures due to resources not being picked up in src/it/resources'. (running the integration tests via command line: sbt it:test works just fine). As a work around, we have found the simply 'touching' a file in the src/it/resources folder will cause IntelliJ to pickup the src/it/resources and the tests start working properly.

0

Please sign in to leave a comment.