Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Using IntelliJ IDEA 14.0.2, I have imported a gradle java project. We have set up a sourceSet and configuration to separate integration tests from unit tests. (our integration tests are in the test source tree, but in their own package). Relevant bits from the 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 up the source of an integration test in IntelliJ and right-click to run it, IntelliJ launches the "test" task rather than the "integTest" task. How do I get IntelliJ to launch the correct task?

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

like image 972
AndyL Avatar asked Feb 04 '15 05:02

AndyL


1 Answers

Follow this: gradle settings > Gradle > Runner and check Delegate IDE build/run actions to gradle. Then apply and Ok.

Good luck!

like image 83
AbbasPirmoradi Avatar answered Oct 08 '22 17:10

AbbasPirmoradi