Home

Awesome

Gradle Integration Testing Plugin

Build Status Coverage Status Gradle Plugin

There are plugin that allow to configure integration tests same way as unit tests in simple way

Build

To build the project it is require to execute

./gradlew clean build 

Documentation

Content:

  1. Quick Start
  2. Source Set
  3. Integration Test Task
  4. Dependencies Management
  5. Skip Tests
  6. Configurable Parameters

Quick Start

To add itest plugin to your project it will require to add next code to the build.gradle

plugins {
    id 'com.softeq.gradle.itest' version '1.0.4'
}

Or with Kotlin

plugins {
  id("com.softeq.gradle.itest") version "1.0.4" 
}

After that you will have possibilities to write tests to the itest/ folder.

To run the tests you just need to execute in your project

./gradlew clean build

Source Set

There are by default application add new source set to the project with name itest. To change name of the source set it is possible to use name configuration parameter. In this case location of integration test sources will be at folder with specified name.

With Groovy / Kotlin

itestSourceSet {
    name = "integrationTest"
}

Also there are possible to customize compile classpath and runtime classpath of the source set

Groovy

itestSourceSet {
    name = "integrationTest"
    compileClasspath = sourceSets.main.compileClasspath
    runtimeClasspath = sourceSets.main.runtimeClasspath
}

Kotlin

itestSourceSet {
    name = "integrationTest"
    compileClasspath = sourceSets["main"].compileClasspath
    runtimeClasspath = sourceSets["main"].runtimeClasspath
}

Integration Test Task

Current plugin also configure task integrationTest that extends standard Test task of the Gradle. Configuration parameters for this task you may find there

JUnit 5

To add support of JUnit 5 you will require to specify at configuration task

Groovy

integrationTest {
    useJUnitPlatform()
}

Kotlin

tasks.withType<Test> {
    useJUnitPlatform()
}

TestNG

To use TestNG for integration testing of you application it will require to specify next configuration for the integrationTest task

Groovy

integrationTest {
    useTestNG()
}

Kotlin

tasks.withType<Test> {
    useTestNG()
}

Spock

To use Spock framework with the plugin it will require just to add the Spock dependencies

Groovy / Kotlin

dependencies {
    itestImplementation("org.spockframework:spock-core:1.3-groovy-2.5")
}

Dependencies Management

There are possible to specify additional dependencies for the integration test classes

Standard Configurationitest ConfigurationDescription
implementationitestImplementationImplementation dependencies scope
compileOnlyitestCompileOnlyCompile Only dependencies scope
runtimeOnlyitestRuntimeOnlyRuntime Only dependencies scope

You can specify this dependencies in the dependencies section of the build.gradle file

Groovy

dependencies {
    itestRuntimeOnly 'com.h2database:h2:1.0.60'
}

Kotlin

dependencies {
    itestRuntimeOnly("com.h2database:h2:1.0.60")
}

Skip Tests

To skip integration tests you need to provide -PdisableIntegrationTests option to the gradle.

For instance

gradlew clean build -PdisableIntegrationTests

Alternative options to disable integration and unit tests you can find below

gradlew clean build -x test -x integrationTest

Configurable Parameters

There are table with available plugin configuration parameters

ParamParent ConfigurationDefault ValueDescription
nameitestSourceSet"itest"There are name of the folder with integration test sources
compileClasspathitestSourceSetMain SourceSet output and classpathThere are classpath of the compiler to build integration tests
runtimeClasspathitestSourceSetMain SourceSet output and runtime classpathThere are runtime classpath that will be used during integration tests evaluation
Gradle Test ParamsintegrationTest-There are standard Gradle Test task configuration
useJUnitPlatform()integrationTest-There are option to enable JUnit 5 tests execution
useTestNG()integrationTest-There are option to enable TestNG evaluation support

License

MIT