Gradle Project Tests
Posted: 6 Jun 2020, 9:59am - Saturday

The Error:

gradle Caused by: org.junit.platform.commons.PreconditionViolationException: Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath

I've been writing tests on my java gradle project and I thought the tests was running every time I compile. I'm using IntelliJ IDEA and when I right click the test folder and `Run All Tests`, seems to work well.

Then I found out that it wasn't running at all when I ran the report.

gradle didn't find my tests

"Five hours later..." I almost gave up and decided to go back to maven. Then thought maybe I will search the error one last time. Landed to this page: https://discuss.gradle.org/t/gradle-4-6-and-junit-5/26061 -- then decided to give one last try. So I change my build.gradle

plugins {
    id 'java'
    id 'project-report'
}

group 'nz.camilord.alphaone.sample'
version '1.0.0-SNAPSHOT'

sourceCompatibility = 11
targetCompatibility = 11

repositories {
    mavenCentral()
}

dependencies {
    compile 'postgresql:postgresql:9.0-801.jdbc4'
    compile 'com.google.code.gson:gson:2.8.0'
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.2'
    //testCompile 'junit:junit:4.13'
}

to this new configuration:

plugins {
    id 'java'
    id 'project-report'
}

group 'nz.camilord.alphaone.sample'
version '1.0.0-SNAPSHOT'

sourceCompatibility = 11
targetCompatibility = 11

repositories {
    mavenCentral()
}

dependencies {
    compile 'postgresql:postgresql:9.0-801.jdbc4'
    compile 'com.google.code.gson:gson:2.8.0'
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.2'
    testCompile 'org.jetbrains.spek:spek-junit-platform-engine:1.0.89'
    testRuntime 'org.junit.jupiter:junit-jupiter-engine'
    //testCompile 'junit:junit:4.13'
}

test {
    useJUnitPlatform()
}

configurations {
    externalLibraries
    compile.extendsFrom (externalLibraries)
}

... and the result is a success! It works!