Run modular project tests in Gradle (JUnit5 + TestFX)

I made a detour until I could do it, so make a note. The environment is IntelliJ. I don't know because I don't use Eclipse.

You can use org.javamodularity.moduleplugin to run modular project tests without any special configuration, but if you use TestFX Had to make the module visible using the JVM's'--add-opens' option.

Below is a sample build.gradle

build.gradle


plugins {
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.7'
    id 'org.beryx.jlink' version '2.10.4'
    id "org.javamodularity.moduleplugin" version "1.5.0"
}

group 'com.sample'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.12

mainClassName = "$moduleName/com.sample.Main"

repositories {
    mavenCentral()
}

//javafx plugin settings
javafx {
    version = "12"
    modules = ['javafx.controls', 'javafx.fxml']
}

//jlink plugin settings
jlink {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher{
        name = "$moduleName"
    }
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
    testImplementation 'org.junit.jupiter:junit-jupiter-params:5.3.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
    testCompile group: 'org.testfx', name: 'testfx-junit5', version: '4.0.15-alpha'
}

test {
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
    }
    //Options for TestFX
    jvmArgs = [
            '--add-opens', "$moduleName/com.sample.foo=org.testfx.junit5",
            '--add-opens', 'javafx.graphics/com.sun.javafx.application=org.testfx'
    ]
}

Recommended Posts

Run modular project tests in Gradle (JUnit5 + TestFX)
Run JUnit and Spock in a maven project
Automatically specify version in gradle project
How to run JUnit in Eclipse
How to run Ant in Gradle
How to filter JUnit Test in Gradle
Do not accept System.in in gradle run
Use static analysis tools in your Gradle project
Run a Spring Boot project in VS Code
Java tips-Create a Spring Boot project in Gradle
Add a project in any folder with Gradle
Run JVM-Math-Language as a Gradle project at hand
View the Gradle task in the Spring Boot project
Refactoring in JUnit