Test packages as dependency

I have two projects:

  • Application project — Project A

  • Project with acceptance tests — Project B

I need to run tests from the project B at project A.

Project B is available for Project A as a dependency.

buid.gradle — Project B:

task sourceJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allJava
}

task testJar(type: Jar, dependsOn: testClasses) {
    classifier = 'tests'
    from sourceSets.test.output 
}

artifacts {
    archives sourceJar, testJar
}

uploadArchives {
    repositories.mavenDeployer {  
        if(project.ext.isReleaseVersion){
            repository (url: '[RepUrl]') {
                authentication (userName: 'user', password: 'pass')
            }  
            println "Upload to internal"
        }else{
            snapshotRepository (url: '[RepUrl]') {
                authentication (userName: 'user', password: 'pass')
            }  
            println "Upload to snapshots"
        }
        
        pom.version = '0.1'
        pom.artifactId = 'acceptance-tests'        
        pom.groupId = 'group' 
}

build.gradle — project A:

dependencies {
    testRuntime ('group:acceptance-tests:latest.release:tests')
}

When I run gradlew test int the project A is not carried out a single test.

Tell me, please , where is my mistake.

The Test task won’t execute tests located inside a JAR. The test classes need to be unpacked somewhere and configured via the testClassesDir in order for the tests to be located and executed.

Thank you!

I have a few more questions . Maybe you can help .

I tried:

configurations {
    acceptanceTests
}
 
dependencies {    
      acceptanceTests   ('group:acceptance-tests:latest.release:tests')
}



task extractAcceptanceTestsSources(type: Copy) {
    from { 
        configurations.acceptanceTests.collect { zipTree(it) }
    }
    into "$buildDir/classes/test/"
    include "path/to/test/classes/**"
}

task extractAcceptanceTestsResources(type: Copy) {
    from { 
        configurations.acceptanceTests.collect { zipTree(it) }
    }
    into "$buildDir/resources/test/"
    include "stories/**" //Test resources with jbehave stories
}

test.doFirst{
    extractAcceptanceTestsSources //It does not start
    extractAcceptanceTestsResources  //It does not start
}

test {
    testClassesDir = project.sourceSets.test.output.classesDir + files("$buildDir/classes/test/")
    //How add test resources?
}

1 ) How to perform a task extractAcceptanceTestsSources and task extractAcceptanceTestsResources before the test .

  1. How set test resources dir for test task?

  2. To test out of the B needed depending, for example jbehave. How to make sure that they hit the PROJECT A.

Perhaps all this ? Or is it better not to do it ?