jeudi 30 août 2018

gradle : java tests ran twice

I am making a skeletton of a java project; the gradle build file has an annoying problem : tests are ran twice, one time by the task 'JUnitPlatformTest' and a second time by the task 'test'.

The first one seems to trigger the second, so I can't disable it, and I would like to keep the second one as there is a little difference between them : the first one is in the console (of intelliJ) and the second uses the integrated intelliJ window.

here is gradle.build

buildscript {
    repositories {
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.3'
        classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
        classpath 'eu.appsatori:gradle-fatjar-plugin:0.3'
    }
}

plugins {
    id 'java'
    id 'edu.sc.seis.launch4j' version '2.4.4'
}

apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'javafx-gradle-plugin'
apply plugin: 'eu.appsatori.fatjar'

junitPlatform {
    platformVersion '1.0.3'
    reportsDir file('build/test-results/junit-platform')
    enableStandardTestTask true
    //show results summary even on success.
    details details.SUMMARY
    filters {
        tags {
            // Framework tests need to be run only when required to verify that this framework is still working.
            exclude "Framework"
        }
        includeClassNamePatterns '.*Test', '.*Tests'
    }
}



group 'lorry'
version '1'

sourceCompatibility = 1.8
//mainClassName="imports.ColorfulCircles"

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    def final junitVersion = "5.2.0"
    compile group: 'com.google.inject', name: 'guice', version: '4.1.0'
    compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
    compile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitVersion
    //compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.11.0'
    compile group: 'org.assertj', name: 'assertj-core', version: '3.9.0'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'

    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junitVersion
    testCompile group: 'org.mockito', name: 'mockito-core', version: '2.7.22'

    testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitVersion

    compile 'org.hamcrest:hamcrest-all:1.3'

    testCompile "org.testfx:testfx-core:4.0.13-alpha"
    testCompile 'org.testfx:testfx-junit5:4.0.13-alpha'
    testRuntime 'org.testfx:openjfx-monocle:8u60-b27'

}

test {
    useJUnitPlatform()
    jvmArgs = [
            "-Dtestfx.robot=glass",
            "-Dtestfx.headless=true",
            "-Dprism.order=sw",
            "-Dprism.text=t2k",
            "-Dheadless.geometry=1920x1200-32"
    ]
}

test.dependsOn 'clean'

jfx {
    // minimal requirement for jfxJar-task
    mainClass = 'imports.ColorfulCircles'

    // minimal requirement for jfxNative-task
    vendor = 'lolveley'
}

jar {
    baseName = 'executable3'
    version =  ''
    manifest {
        attributes(
                'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
                'Main-Class': 'imports.ColorfulCircles'
        )
    }
}
launch4j {
    outfile='bibliotek-v3.exe'
    mainClassName = 'imports.ColorfulCircles'
    icon = "${projectDir}\\icons\\hands2.ico"
    copyConfigurable = project.tasks.fatJar.outputs.files
    jar = "lib/${project.tasks.fatJar.archiveName}"
    //headerType = "console"
    //jar = "${buildDir}\\productFatJar\\fat.jar"
}

junitPlatformTest {
        jvmArgs = [
                "-Dtestfx.robot=glass",
                "-Dtestfx.headless=true",
                "-Dprism.order=sw",
                "-Dprism.text=t2k",
                "-Dheadless.geometry=1920x1200-32"
        ]
    }

and here is the result:

Testing started at 19:25 ...
19:25:01: Executing task 'test'...

> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
> Task :clean
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses
> Task :junitPlatformTest
constructeur appelé
Before all
Before each
my test 1
Before each
my test 2
This test method should be run
Test run finished after 3630 ms
[         4 containers found      ]
[         0 containers skipped    ]
[         4 containers started    ]
[         0 containers aborted    ]
[         4 containers successful ]
[         0 containers failed     ]
[         7 tests found           ]
[         0 tests skipped         ]
[         7 tests started         ]
[         0 tests aborted         ]
[         7 tests successful      ]
[         0 tests failed          ]
> Task :test
constructeur appelé
Before all
Before each
my test 1
Before each
my test 2
This test method should be run
BUILD SUCCESSFUL in 13s
5 actionable tasks: 5 executed
19:25:15: Task execution finished 'test'.

Aucun commentaire:

Enregistrer un commentaire