0

I haven't been able to get the "tests" parameter of gradle 4.4 and now 4.4.1 to filter JUnit (5.0.2) tests. The following command runs every test no matter what I change "bogus" to:

gradle test --tests bogus

I would expect this command to fail since there is no test called "bogus." I have also tried referring to a legitimate test, and every test is run regardless. My build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.2'
    }
}

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'maven'
apply plugin: 'org.junit.platform.gradle.plugin'

compileJava {
    options.compilerArgs += "-Xlint:unchecked"
}

repositories {
    mavenCentral()
}

dependencies {
    testCompile('org.junit.jupiter:junit-jupiter-api:5.0.1')
    testCompile('org.apiguardian:apiguardian-api:1.0.0')
    testRuntime('org.junit.jupiter:junit-jupiter-engine:5.0.1')
}


// Define the main class for the application
mainClassName = 'CMS'

jar {
    manifest {
        attributes 'Implementation-Title': 'CMS',
                   'Main-Class': 'com.brandli.cms.CMS'
    }
}

junitPlatform {
    filters {
        includeClassNamePattern '.*'
    }
}

junitPlatformTest {
    enableAssertions = true
}

tasks.withType(Test) {
    testLogging {
        exceptionFormat = 'full'
        showStackTraces = true
    }
}

task buildCtags(type: Exec, dependsOn: classes) {
    workingDir 'build'
    commandLine 'ctags', '-R', '-f', 'java.tags', '../src/main/java',
            '../src/test/java'
}

assemble.dependsOn buildCtags

I have tried taking out the junitPlatform, the junitPlatformTest, and the tasks.withType(test) clauses with no change.

My tests only contain the @Test annotation for each method: no other annotations.

Anyone able to get this to work?

EDIT:

This is not a duplicate of How to run only one test class on gradle. The answer to that question recommended using the gradle option that I cannot now get to work, or even be recognized at all.

Steve Brandli
  • 556
  • 4
  • 14
  • When you refer to Gradle xxx as failing, you make it sound like it used to work with Gradle yyy. I’m assuming you didn’t verify that. As for test matches, they are matched by fully-qualified names using ant patterns – Abhijit Sarkar Jan 14 '18 at 00:19
  • I'm relatively new to gradle: have never had this work. If fully-qualified names are required, then wouldn't "bogus" not match to anything and not run any tests? Using the full name of a test class, e.g. "com.brandli.jcrud.db.DbParseTest" also did not work, and neither did "*DbParseTest". – Steve Brandli Jan 14 '18 at 00:22
  • Possible duplicate of [How to run only one test class on gradle](https://stackoverflow.com/questions/22505533/how-to-run-only-one-test-class-on-gradle) – Abhijit Sarkar Jan 14 '18 at 01:48

0 Answers0