Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 运行gradle测试时,NoClassDefFoundError、FxRobotException、FatalBanException和ExecutionException_Java_Unit Testing_Gradle_Noclassdeffounderror_Testfx - Fatal编程技术网

Java 运行gradle测试时,NoClassDefFoundError、FxRobotException、FatalBanException和ExecutionException

Java 运行gradle测试时,NoClassDefFoundError、FxRobotException、FatalBanException和ExecutionException,java,unit-testing,gradle,noclassdeffounderror,testfx,Java,Unit Testing,Gradle,Noclassdeffounderror,Testfx,我正在尝试在脱机机器上使用gradle运行TestFX测试 命令式 gradle -Dtest.single=ViewsTest test 在一台机器上,它运行良好,但在另一台机器上,它失败了 NoClassDefFoundError: org.testfx.api.FxRobotException 这可能意味着这里有双重错误。一个未知错误发生在运行测试时,另一个错误发生在TestFX试图生成关于它的异常时 我对后一个很感兴趣:为什么格拉德尔没有看到这门课 同时,我编写了测试来检查类是否可用

我正在尝试在脱机机器上使用gradle运行TestFX测试

命令式

gradle -Dtest.single=ViewsTest test
在一台机器上,它运行良好,但在另一台机器上,它失败了

NoClassDefFoundError: org.testfx.api.FxRobotException
这可能意味着这里有双重错误。一个未知错误发生在运行测试时,另一个错误发生在TestFX试图生成关于它的异常时

我对后一个很感兴趣:为什么格拉德尔没有看到这门课

同时,我编写了测试来检查类是否可用

 @Test
   public void causes_exception_on_unknown_button() {
      try {
         point(new Predicate<Node>() {
            @Override
            public boolean apply(Node input) {
               return false;
            }
         });
      }
      catch (FxRobotException e) {
         System.out.println("Expected exception found");
         return;
      }
      throw new AssertionError("No expected exception found");
   }
怎么可能

更新

如果我跑

gradle -Dtest.single=ViewsTest test -i
更多信息

出现以下异常:

 java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: org.springframework.beans.F
atalBeanException

        Caused by:
        java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException

            Caused by:
            java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException

    org.testfx.api.FxRobotException: the query "#menuFile" returned no nodes.
奇怪的是,现在我们确实看到了来自FxRobotException的实际消息,而class def error现在与fatalbanexception的不同类相关。同时,根本原因似乎是某个地方的执行异常

更新2

build.gradle如下所示。注意,它是本地的:

buildscript {
    repositories {
        mavenLocal()
    }

    dependencies {
        classpath "com.github.jengelman.gradle.plugins:shadow:1.2.3"
        classpath 'org.ajoberstar:gradle-git:1.5.1'
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: 'antlr'

ext {

    try {
        revision = org.ajoberstar.grgit.Grgit.open().head().abbreviatedId
    }
    catch(all) {
        revision = 'SNAPSHOT'
    }
}


project.group = 'com.cireca'
version = '0.1.20.' + getDate() + '-' + revision

description = """"""

sourceCompatibility = 1.8
targetCompatibility = 1.8





repositories {
    mavenLocal()
    flatDir {
        dirs 'lib'
    }

}

dependencies {
    ext.springVersion = '4.2.6.RELEASE'
    ext.junitVersion = '4.12'


    antlr "org.antlr:antlr4:4.5" // use ANTLR version 4

    compile("org.hibernate:hibernate-entitymanager:5.1.0.Final")
    compile("com.opencsv:opencsv:3.7")
    compile("com.cireca.overlaywidget:OverlayWidget:1.0-SNAPSHOT")
    compile("org.springframework:spring-context:$springVersion")
    compile("org.springframework:spring-beans:$springVersion")
    compile("org.springframework:spring-jdbc:$springVersion")
    compile("org.springframework:spring-orm:$springVersion")
    compile('mysql:mysql-connector-java:5.1.38')
    compile('org.apache.commons:commons-dbcp2:2.1.1')
    compile('org.controlsfx:controlsfx:8.40.12')
    compile('org.apache.commons:commons-io:1.3.2')
    compile('org.apache.commons:commons-csv:1.2')
    compile('org.apache.commons:commons-collections4:4.1')
    compile('org.apache.commons:commons-lang3:3.4')
    compile('commons-beanutils:commons-beanutils:1.9.2')
    compile('com.google.guava:guava:19.0')
    compile('org.cache2k:cache2k-core:0.25-BETA')
    compile('it.unimi.dsi:fastutil:7.0.12')
    compile('org.jadira.usertype:usertype.core:5.0.0.GA')
    compile('joda-time:joda-time:2.9.2')
    compile group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.22'
    compile group: 'org.fxmisc.easybind', name: 'easybind', version: '1.0.3'
    compile group: 'io.reactivex', name: 'rxjavafx', version: '2.0.2'
    compile name: 'orsoncharts-1.5'
    compile name: 'fxgraphics2d-1.3'
    compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
    compile group: 'org.eclipse.swt', name: 'org.eclipse.swt.win32.win32.x86', version: '4.6.1'
    compile group: 'org.eclipse.swt', name: 'org.eclipse.swt.win32.win32.x86_64', version: '4.6.1'

    testCompile("org.springframework:spring-test:$springVersion")
    testCompile("junit:junit:$junitVersion")
    testCompile('org.assertj:assertj-core:3.5.2')
    testCompile group: 'org.testfx', name: 'testfx-junit', version: '4.0.4-alpha'
    testCompile group: 'org.testfx', name: 'testfx-core', version: '4.0.4-alpha'


}

sourceSets {
    demo
    attempts {
        compileClasspath += main.output
        runtimeClasspath += main.output
    }
    tools
    antlrGenerated {
        java {

        }
    }
}

jar {
    manifest {
        attributes 'Main-Class': 'com.cireca.Main'
    }

}


attemptsClasses.dependsOn build

task wrapper(type: Wrapper) {
    gradleVersion = '2.9'
}


generateGrammarSource {
    maxHeapSize = "64m"
    arguments += ["-visitor", "-long-messages"]
}

task packageTests(type: Jar) {
    from sourceSets.test.output
}

def getDate() {
    def date = new Date()
    def formattedDate = date.format('yyyyMMddHHmm')
    return formattedDate
}

task zip4BuildServer(type: Zip) {
    classifier = 'src'
    from projectDir
    include 'src/**/*'
    include 'lib/**/*'
    include 'gradle/**/*'
    include 'build.gradle'
    include 'settings.gradle'
    include 'data_source.xml'
    include 'gradlew'
    include 'gradlew.bat'
    archiveName "${baseName}-${getDate()}-${revision}.${extension}"
}

test {
    testLogging {
        // Show that tests are run in the command-line output
        events 'started', 'passed'
    }
}
错误跟踪如下所示:

java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException
    at org.testfx.util.WaitForAsyncUtils.waitFor(WaitForAsyncUtils.java:161)
    at org.testfx.api.FxToolkit.waitForSetup(FxToolkit.java:269)
    at org.testfx.api.FxToolkit.setupApplication(FxToolkit.java:175)
    at org.testfx.framework.junit.ApplicationTest.internalBefore(ApplicationTest.java:54)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:105)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:56)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:64)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:106)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:360)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException
    at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:476)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:455)
    at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
    at org.testfx.toolkit.impl.ToolkitServiceImpl.lambda$setupApplication$60(ToolkitServiceImpl.java:144)
    at org.testfx.util.WaitForAsyncUtils.callCallableAndSetFuture(WaitForAsyncUtils.java:363)
    at org.testfx.util.WaitForAsyncUtils.lambda$async$8(WaitForAsyncUtils.java:88)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    ... 3 more
Caused by: java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at com.cireca.filterwidget.javafx.spring.SpringFX.initializeSpringContext(SpringFX.java:65)
    at com.cireca.filterwidget.javafx.spring.SpringFX.initialize(SpringFX.java:123)
    at com.cireca.filterwidget.javafx.spring.SpringFX.init(SpringFX.java:73)
    at com.cireca.testfx.TestFXUtils.startLDT(TestFXUtils.java:38)
    at com.cireca.testfx.MainUITest.start(MainUITest.java:37)
    at org.testfx.framework.junit.ApplicationAdapter.start(ApplicationAdapter.java:54)
    at org.testfx.toolkit.impl.ApplicationServiceImpl.lambda$start$61(ApplicationServiceImpl.java:62)
    at org.testfx.util.WaitForAsyncUtils.callCallableAndSetFuture(WaitForAsyncUtils.java:363)
    at org.testfx.util.WaitForAsyncUtils.lambda$asyncFx$9(WaitForAsyncUtils.java:115)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    ... 1 more
更新3

依赖项检查的结果

>gradle dependencyInsight --dependency spring-beans --configuration testRuntime
:dependencyInsight
org.springframework:spring-beans:4.2.6.RELEASE
+--- testRuntime
+--- org.springframework:spring-aop:4.2.6.RELEASE
|    \--- org.springframework:spring-context:4.2.6.RELEASE
|         \--- testRuntime
+--- org.springframework:spring-context:4.2.6.RELEASE (*)
+--- org.springframework:spring-jdbc:4.2.6.RELEASE
|    +--- testRuntime
|    \--- org.springframework:spring-orm:4.2.6.RELEASE
|         \--- testRuntime
+--- org.springframework:spring-orm:4.2.6.RELEASE (*)
\--- org.springframework:spring-tx:4.2.6.RELEASE
     +--- org.springframework:spring-jdbc:4.2.6.RELEASE (*)
     \--- org.springframework:spring-orm:4.2.6.RELEASE (*)

(*) - dependencies omitted (listed previously)

BUILD SUCCESSFUL

Total time: 5.694 secs


>gradle dependencyInsight --dependency spring-core --configuration testRuntime
:dependencyInsight
org.springframework:spring-core:4.2.6.RELEASE
+--- org.springframework:spring-aop:4.2.6.RELEASE
|    \--- org.springframework:spring-context:4.2.6.RELEASE
|         \--- testRuntime
+--- org.springframework:spring-beans:4.2.6.RELEASE
|    +--- testRuntime
|    +--- org.springframework:spring-context:4.2.6.RELEASE (*)
|    +--- org.springframework:spring-jdbc:4.2.6.RELEASE
|    |    +--- testRuntime
|    |    \--- org.springframework:spring-orm:4.2.6.RELEASE
|    |         \--- testRuntime
|    +--- org.springframework:spring-orm:4.2.6.RELEASE (*)
|    +--- org.springframework:spring-aop:4.2.6.RELEASE (*)
|    \--- org.springframework:spring-tx:4.2.6.RELEASE
|         +--- org.springframework:spring-jdbc:4.2.6.RELEASE (*)
|         \--- org.springframework:spring-orm:4.2.6.RELEASE (*)
+--- org.springframework:spring-context:4.2.6.RELEASE (*)
+--- org.springframework:spring-expression:4.2.6.RELEASE
|    \--- org.springframework:spring-context:4.2.6.RELEASE (*)
+--- org.springframework:spring-jdbc:4.2.6.RELEASE (*)
+--- org.springframework:spring-orm:4.2.6.RELEASE (*)
+--- org.springframework:spring-test:4.2.6.RELEASE
|    \--- testRuntime
\--- org.springframework:spring-tx:4.2.6.RELEASE (*)

(*) - dependencies omitted (listed previously)

BUILD SUCCESSFUL

Total time: 5.557 secs
确保testfx junit和ViewsTest由同一个类加载器加载

可能的原因:

包含ViewsTest.class的jar位于%JAVA\u HOME%\jre\lib中 包含ViewsTest.class的项目被添加到gradle中的buildscript{classpath…}}块中 快速浏览一下,我发现org.springframework.beans.FatalBeanException位于SpringBeans和SpringCore依赖项中

您可能希望使用查看这两个依赖项的情况

例如:在命令行中键入以下内容

gradle dependencyInsight --dependency spring-beans --configuration testRuntime
gradle dependencyInsight --dependency spring-core --configuration testRuntime

我怀疑在您的类路径的某个地方,您的一个依赖项需要某个版本的SpringBeans或SpringCore,但Gradle正在用另一个版本来解决这个问题

这是如何解释的,在另一台机器上运行的测试?Jar在%JAVA\u HOME%\jre\lib中会解释它。或者你可能在%GRADLE\u HOME%\lib中添加了一个jar?我用不同的名称编写了不同的测试类,其行为方式相同。请提供更多的构建。GRADLE。。。特别是配置testCompile和testRuntime类路径的位。还有anybuildscript.classpath配置。以及测试任务本身的任何配置。请参阅flatDir文档,其中指出,这种类型的存储库不支持任何元数据格式,如Ivy XML或Maven POM文件。相反,Gradle将动态生成一个模块描述符,而不包含任何依赖项信息。也许它是lib文件夹中的一个jar,希望使用不同版本的springdir。使用flatDir存储库确实不是一个好主意。可传递的依赖项信息丢失。如果要存储在目录中,可以使用maven{url uri'path/to/local/dir'},因此也可以将pom元数据xml存储在目录中
gradle dependencyInsight --dependency spring-beans --configuration testRuntime
gradle dependencyInsight --dependency spring-core --configuration testRuntime