首页 > 解决方案 > 使用 JUnit 5 在 Gradle 上设置 TestFX

问题描述

我正在努力获得用于 Gradle 项目的 TestFX 设置。我按照https://github.com/TestFX/TestFX/blob/master/README.md上的说明进行操作,但它似乎仍然给我带来了问题。任何想法为什么它没有找到方法?

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method testCompile() for arguments [org.testfx:testfx-core:4.0.16-alpha] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

gradle.build

plugins {
    // Apply the application plugin to add support for building a CLI application in Java.
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.9'
    id 'jacoco'
}

repositories {
    // Use JCenter for resolving dependencies.
    jcenter()
    mavenCentral()
}

dependencies {
    // Use JUnit Jupiter API for testing.
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'

    // Use JUnit Jupiter Engine for testing.
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

    // This dependency is used by the application.
    implementation 'com.google.guava:guava:29.0-jre'

    // Ikonli Text Icons
    implementation 'org.kordamp.ikonli:ikonli-javafx:12.1.0'
    implementation 'org.kordamp.ikonli:ikonli-fontawesome5-pack:12.1.0'
    implementation 'org.kordamp.ikonli:ikonli-materialdesign2-pack:12.1.0'
    implementation 'org.kordamp.ikonli:ikonli-material2-pack:12.1.0'

    // TestFX
    testCompile "org.testfx:testfx-core:4.0.16-alpha"
    testCompile 'org.junit.jupiter:junit-jupiter-api:5.5.1'
    testCompile "org.testfx:testfx-junit5:4.0.16-alpha"
    testCompile group: 'org.hamcrest', name: 'hamcrest', version: '2.1'
}

application {
    // Define the main class for the application.
    mainClass = 'App'
}

tasks.named('test') {
    // Use junit platform for unit tests.
    useJUnitPlatform()
}

javafx {
    version = "17"
    modules = ['javafx.controls', 'javafx.fxml']
}

jacoco {
.
.
.

注意:我确实尝试过改变行为plugin{id 'org.openjfx.javafxplugin' version '0.0.8'}并且javafx {version = '12'}没有改变行为。

标签: gradlejunit5testfx

解决方案


推荐阅读