How to run integration tests from the IntelliJ context menu for a gradle project?

Using IntelliJ IDEA 14.0.2, I imported the gradle java project. We set sourceSet and configuration to separate integration tests from unit tests. (Our integration tests are in the test source tree, but in their own package). The corresponding bits from build.gradle are:

sourceSets { test { java { exclude '**/it/**' } } integTest { java { srcDir 'src/test/java' include '**/it/**' } resources { srcDir 'src/test/resources' } compileClasspath += sourceSets.main.output + sourceSets.test.output + configurations.testRuntime runtimeClasspath += sourceSets.main.output + sourceSets.test.output + configurations.testRuntime } } configurations { integTestCompile.extendsFrom testCompile integTestRuntime.extendsFrom testRuntime } idea { module { scopes.TEST.plus += [ configurations.integTestCompile ] } } task integTest(type: Test) { testClassesDir = sourceSets.integTest.output.classesDir classpath = sourceSets.integTest.runtimeClasspath } 

This works fine from the command line. But when I open the source of the integration test in IntelliJ and right-click to launch it, IntelliJ runs the "test" task, not the "InteTest" task. How to get IntelliJ to run the correct task?

Alternatively, how can I make the test task delegate another task based on the contents of "-tests" arg?

+11
intellij-idea unit-testing gradle
source share
2 answers

Right-click on the test in the file and you should see a menu item for Create Run Configuration > . Select this dialog in the dialog box, change the Tasks parameter. Change this to integTest and click OK. From now on, you may have to run the test using the menu system, not the context system. those. Run > Run...

0
source share

Follow these steps: configure gradle> Gradle> Runner and select the Delegate IDE check box to build / run actions on gradle. Then apply and approx.

Good luck

0
source share

All Articles