0

I use Mockito in my Java tests, and have some Scala tests. If I include Scala testCompile dependency then Mockito fail to create a spy when running in IntelliJ, and I get ClassCastException exception.

Can I separate the scala and the java tests, so the java tests have some dependencies and the scala has other dependencies?

arberg
  • 4,148
  • 4
  • 31
  • 39
  • Turns out it was IntelliJ that messed up, not Scala, Gradle or Mockito, it runs when running direcltly in Gradle . I think this mention my issue: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000191604-Unit-Tests-run-from-Gradle-and-IDEA-differ – arberg Feb 18 '18 at 16:35

1 Answers1

0

If you don't have to run all your tests in the same build, you can use dependency profiles. Lets say scalaTests and javaTests.
And you can group test dependencies like below

dependencies {
    ....
    if (project.hasProperty('scalaTests')) {
        //scala test dependencies here
    }
    else if (project.hasProperty('javaTests'))
       //java test dependencies here
    }
 }

You also have to run only Scala tests when you are using Scala profile(same for java test) You can run gradle with scalaTests profile like this gradle -PscalaTests .. (same for java case)

For running specific tests

How to run only one test class on gradle

Gradle run only one test suite

For profile details.

https://gist.github.com/szpak/1499336

Maven profiles equivalent of Gradle

miskender
  • 7,460
  • 1
  • 19
  • 23