I have a project maven-based. Some tests are in spock, others in JUnit. Imagine a project with legacy tests, which migration is still in-progress.
Maven is set to run the tests with groovy (spock) mocks activated only in case of a groovy file, whereas for JUnit tests spock tests are deactivated, in order to not interfere with its own mocks (mockito/mockk or whathever). Everything works fine if executed by maven. The key is passing as an argLine
the proper value -Dspock-mockable.disabled=true/false
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>run-unit-tests</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<forkCount>1</forkCount>
<argLine>-Dspock-mockable.disabled=true</argLine>
<includes>
<include>**/*UnitTest.kt</include>
</includes>
<excludes>
<exclude>**/*.groovy</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>run-kt-tests</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<forkCount>1</forkCount>
<argLine>-Dspock-mockable.disabled=true</argLine>
<includes>
<include>**/*.kt</include>
</includes>
<excludes>
<exclude>**/*.groovy</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>run-spock-tests</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<forkCount>1</forkCount>
<argLine>-Dspock-mockable.disabled=false</argLine>
<includes>
<include>**/*.groovy</include>
</includes>
<excludes>
<exclude>**/*.kt</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
The problem: if running as a single test/class test from IntelliJ, the test runner does not evaluate the include/exclude rules, and the variable is not set by default.
I should “Modify run configuration” each time I touch a groovy test, in order to add it as an argument which is cumbersome.
[][1
I’m trying to find a way to make it work with zero configuration (or just a one-shot setup) and let the IDE pass the variable to true/false according to the type of test.
What I can do is crerating a run configuration, but for running all the tests each time, which is cumbersome.