简体   繁体   中英

How to run tests from a test-jar in gradle?

I have a multi project build in gradle. In project gradle-playground-a I'm creating a test-jar with some junit tests:

plugins {
    id 'java'
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

repositories {
    mavenCentral()
}

test.enabled = false

configurations {
    testArtifacts.extendsFrom testRuntime
}
task testJar(type: Jar) {
    classifier "test"
    from sourceSets.test.output
}
artifacts {
    testArtifacts testJar
}

Now I would like to run the tests of the test-jar within another project gradle-playground-b . Therefore I have:

plugins {
    id 'java'
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testRuntimeOnly project (path: ":gradle-playground-a", configuration: 'testArtifacts')
}

repositories {
    mavenCentral()
}

However the tests from the test-jar are not run. When I look at gradles debug output I see that the test-jar is included in the classpath for the test execution of gradle-playground-b .

What I'm trying to do is to have an equivalent of mavens surefire depednenciesToScan functionality.

How do I execute the tests from the test-jar when testing gradle-playground-b ?

I just use a "button" in netbeans on the first project to activate the second project. That's the only way I really know how to do it because I have done sortof limited projects I am pretty sure you could do this in VB with Visual STudio but since your in Java use netbeans and it's free.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM