gpt4 book ai didi

gradle - TestFX Spock Gradle项目Openjdk 11-零测试结果

转载 作者:行者123 更新时间:2023-12-03 05:36:26 26 4
gpt4 key购买 nike

为什么我的Spock测试没有执行,执行时我的测试结果为为零:

./gradlew clean test

与我的 TestFX Spock Gradle项目 Openjdk 11 吗?

这是零测试结果:
enter image description here

我的Spock测试类可以编译,但无法执行。

这是我的 控制台:
Working Directory: /home/~/EclipseProjects/gradleTestfxSpock
Gradle user home: /home/~/.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 5.0
Java Home: /usr/lib/jvm/jdk-11.0.2+9
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: clean test


> Configure project :
Found module name 'mtd'

> Task :clean
> Task :compileJava
> Task :compileGroovy NO-SOURCE
> Task :processResources
> Task :classes
> Task :compileTestJava NO-SOURCE
> Task :compileTestGroovy
> Task :processTestResources
> Task :testClasses
> Task :test

BUILD SUCCESSFUL in 6s
6 actionable tasks: 6 executed

这是我的 build.gradle :
plugins {    
id 'org.openjfx.javafxplugin' version '0.0.7'
id 'application'
id 'groovy'
}

mainClassName = 'mtd/gradleTestfxSpock.Main'

sourceCompatibility = 11
targetCompatibility = 11

repositories {
jcenter()
}

dependencies {
implementation 'org.testfx:testfx-spock:4.0.15-alpha'
testCompile 'org.testfx:testfx-core:4.0.15-alpha'

testCompile (group: 'org.spockframework', name: 'spock-core', version: '1.3-groovy-2.5')
testCompile ('org.codehaus.groovy:groovy-all:2.5.6')
testRuntime(
'com.athaydes:spock-reports:1.2.7',
'cglib:cglib-nodep:3.2.4'
)
}

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

compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls',
'--add-modules', 'javafx.fxml',
'--add-modules', 'javafx.web'
]
}
}

test {
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'ALL-MODULE-PATH',
'--add-exports', 'javafx.graphics/com.sun.javafx.application=org.testfx'
]
}
}

这是我的 module-info.java :
module mtd {

requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
requires javafx.web;

requires org.testfx;
requires testfx.spock;

opens gradleTestfxSpock to javafx.graphics;

exports gradleTestfxSpock;
}

这是我的 Spock测试代码:
package gradleTestfxSpock;

import org.testfx.framework.spock.ApplicationSpec;
import javafx.stage.Stage


public class MainTest extends ApplicationSpec{


def "Main Test 01"() {
expect:
println("you are in Main test 01");
}

@Override
public void start(Stage arg0) throws Exception {
// TODO Auto-generated method stub
}


}

这是我的 JavaFX代码:
package gradleTestfxSpock;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("/fxml/sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}


public static void main(String[] args) {
launch(args);
}
}

Controller :
package gradleTestfxSpock;
public class Controller {
}

这是我的 eclipse gradle项目结构:

enter image description here

在其他Eclipse gradle项目中,我已经成功执行了 TestFX Junit4 测试 而没有Spock :

enter image description here

并且我分别成功地执行了相同的 Spock测试(不带TestFX )和 (不带JUnit ):

enter image description here

我确实在此Spock测试中注意到了一些警告:
Working Directory: /home/~/EclipseProjects/gradleSpock
Gradle user home: /home/~/.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 5.0
Java Home: /usr/lib/jvm/jdk-11.0.2+9
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: clean test

> Task :clean
> Task :compileJava
> Task :compileGroovy NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes
> Task :compileTestJava NO-SOURCE
> Task :compileTestGroovy
> Task :processTestResources NO-SOURCE
> Task :testClasses

> Task :test
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/home/dm/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.5.6/6936e700f0fb1b50bac0698ada4347a769d40199/groovy-2.5.6.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

BUILD SUCCESSFUL in 9s
4 actionable tasks: 4 executed

结论

如果使用JUnit的TestFX可以工作,并且单独使用Spock可以工作,但是使用Spock的TestFX不能工作,那么配置有问题吗:
'org.testfx:testfx-spock:4.0.15-alpha'

任何想法或帮助,不胜感激。

ps忘了说我也在Netbeans中创建了TestFX / Spock项目,并复制了eclipse项目,结果还是一样!

更多测试

不幸的是,按照伦纳德·布鲁宁斯(Leonard Bruenings)的以下很好的建议进行的更多测试组合无法正常工作。

我修改后的module-info.java看起来像:
module mtd {

requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
requires javafx.web;

requires org.testfx.junit;
requires org.testfx;
requires testfx.spock;
requires spock.core;
requires junit;

opens gradleTestfxSpock to javafx.graphics, org.testfx, testfx.spock, spock.core, junit, org.testfx.junit;

exports gradleTestfxSpock;
}

并将其添加到gradle.build依赖项中,以防万一:
implementation 'org.testfx:testfx-junit:4.0.15-alpha'

仍然没有喜悦...

最佳答案

解决方案

我发现这个插件是个问题,并且正在停止成功执行我的Spock测试:

`plugins {    
id 'org.openjfx.javafxplugin' version '0.0.7'
}`

当我从build.gradle中删除它时, TestFX Spock 测试正常。

通过重新构建的build.gradle和module-info.java,我可以成功执行Spock测试:
plugins { 
id 'application'
id 'groovy'
}

ext {
moduleName = "mtd"
mainQualifiedClassName = "gradleTestfxSpock.Main"
}

application {
mainClassName = "$moduleName/$mainQualifiedClassName"
}

sourceCompatibility = 11
targetCompatibility = 11

repositories {
jcenter()
}

dependencies {
implementation("org.openjfx:javafx-fxml:11:linux")
implementation("org.openjfx:javafx-web:11:linux")
implementation("org.openjfx:javafx-media:11:linux")
implementation("org.openjfx:javafx-base:11:linux")
implementation("org.openjfx:javafx-graphics:11:linux")
implementation("org.openjfx:javafx-controls:11:linux")

testImplementation ('org.testfx:testfx-spock:4.0.15-alpha')
testImplementation ('org.testfx:testfx-core:4.0.15-alpha')

testImplementation (group: 'org.spockframework', name: 'spock-core', version: '1.3-groovy-2.5')
testImplementation ('org.codehaus.groovy:groovy-all:2.5.6')

testRuntimeOnly (
'com.athaydes:spock-reports:1.2.7',
'cglib:cglib-nodep:3.2.4'
)
}


compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls',
'--add-modules', 'javafx.fxml',
'--add-modules', 'javafx.web'
]
}
}

run {
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--patch-module', "$moduleName=" + files(sourceSets.main.output.resourcesDir).asPath,
'--module', mainClassName
]
}
}

我需要添加到build.gradle的运行部分中:
  • '--module', mainClassName
    -这样就可以找到mainClassName
  • '--patch-module', "$moduleName=" + files(sourceSets.main.output.resourcesDir).asPath
    -提供对资源文件的访问,例如getClass().getResource("/fxml/sample.fxml")

  • module mtd {

    requires javafx.controls;
    requires javafx.fxml;
    requires transitive javafx.graphics;
    requires javafx.web;


    exports gradleTestfxSpock;
    }

    关于gradle - TestFX Spock Gradle项目Openjdk 11-零测试结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55894842/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com