1

I have this root build.gradle

repositories {
    jcenter()
}

subprojects  {

    apply plugin: 'java'

    group 'me.someone'
    version '1.0.0'

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    repositories {
        jcenter()
        mavenCentral()
    }

    dependencies {
        testImplementation 'junit:junit:4.12'
    }

}

Then I have this child build.gradle

plugins {
    id 'java-library'
    id 'eclipse'
    id "org.springframework.boot" version "2.0.1.RELEASE"
    id 'io.spring.dependency-management' version "1.0.5.RELEASE"
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile project(':foo-jar')

    testImplementation('org.springframework.boot:spring-boot-starter-test')
    testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.18.3'

}

sourceSets {
    main {
        java {
            srcDir 'src/main/java'
        }
    }

    test {
        java.srcDir file('src/int/java')
    }

    itest {
        java {
            srcDir file('src/itest/java')
        }
        //resources.srcDir 'src/itest/resources'
    }
}


test {
    testLogging {
        showStandardStreams = true
        events "passed", "skipped", "failed"
        exceptionFormat = 'full'
    }   
}

task itest(type: Test) {
  testLogging {
        showStandardStreams = true
        events "passed", "skipped", "failed"
        exceptionFormat = 'full'
   }
   itest.mustRunAfter test
}

check.dependsOn itest

bootRun {
    main = 'me.someone.BarServiceApplication'
}

The issue is unit test runs twice but not the integration test. Why is unit test running twice but not integration test? My understanding is when I provided the source folder of integration test, it should run the integration test as well.

cosmos
  • 2,143
  • 2
  • 17
  • 27
  • This may help: https://stackoverflow.com/questions/11581419/how-do-i-add-a-new-sourceset-to-gradle?noredirect=1&lq=1 – Slaw Jun 08 '18 at 04:00

1 Answers1

0

Your task itest needs to have its testClassesDirs configured, that is why it is currently running your unit tests twice. It might also need the classpath configured.

And you should have a look at the Gradle documentation on how to do integration tests for all the details.

Louis Jacomet
  • 13,661
  • 2
  • 34
  • 43