Changing from javaexec to project.test in build.gradle for a Cucumber Java project

34 views Asked by At

I want to implement a retry option for my testing framework. I did some digging around and discovered the option can be incorporated but not as I had the project. I have been trying to convert it from using a javaexec structure to using project.test, but when I go to call my gradle task none of my test steps are called. I may be overlooking something, I am not too familiar with this method of implementation, so any advice would be helpful.

Here is my existing test execution code:

task smoke() {
    dependsOn assemble, compileTestJava
    doLast { runTests('smoke') }
}
task regression() {
    dependsOn assemble, compileTestJava
    doLast { runTests('regression') }
}
task newWork() {
    dependsOn assemble, compileTestJava
    doLast { runTests('newWork') }
}

private ExecResult runTests(String testType) {
    javaexec {
        mainClass = "io.cucumber.core.cli.Main"
        classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
        args = ['--plugin', 'pretty',
                '--plugin', 'json:output/reports/report.json',
                '--plugin', 'html:output/reports/html',
                '--tags', ('@' + testType), '--glue', 'stepDefinitions', 'src/test/resources/features',
                '--tags', 'not @disabled']
    }
}

This is what I've tried implementing:

task smoke() {
    dependsOn assemble, compileTestJava
    doLast { runTests('smoke') }
}
task regression() {
    dependsOn assemble, compileTestJava
    doLast { runTests('regression') }
}
task newWork() {
    dependsOn assemble, compileTestJava
    doLast { runTests('newWork') }
}

private void runTests(String testType) {
    project.test {
        workingDir = file('src/test/resources')
        systemProperty 'cucumber.options', "--tags @${testType} --glue stepDefinitions:src/test/java/stepDefinitions"
        retry {
            maxRetries = 3
            maxFailures = 20
            failOnPassedAfterRetry = false
        }
        reports {
            reports.html.required = true
            reports.html.destination = file('alice/JavelinTAF/output/reports/html')
        }
    }
}

I have checked logs and tried adding debugging statements but have not been able to find what may be wrong. It seems as though the tests are not being found at all. The build is successful but no tests are run. I also have not been able to add the output for .json reports in the relevant section as it throws an error, but that is not as big a deal right now. I have been struggling to find documentation or examples of this, so any advice or examples would be helpful.

0

There are 0 answers