2011-06-16 53 views
2

這裏完成了Gradle noob。我正在嘗試使用Gradle執行Groovy測試。我有一個eclipse項目,我正在運行這些測試,但希望能夠在用戶Gradle的構建服務器上運行這些項目。源代碼編譯但是當執行測試時,我得到一個FileNotFound異常。我看過這個項目,我相信有幾個需要加載的配置文件。在代碼拋出FileNotFound異常的方法有以下線路:Gradle,在哪裏包含testRuntime的配置文件

TestData = new TestConfig("TestConfiguration.xml") 
ErrorMessages = new ErrorMessages("ErrorMessages.xml") 
FieldValidators = new FieldValidators("FieldValidators.xml") 

這些XML文件將在項目文件夾只是增加。我試圖將它們添加到testCompile和testRuntime依賴關係中,但沒有多少好運。我試圖將它們添加到SourceSet的測試任務資源下,但我不確定這是否是正確的方向。有任何想法嗎?

java.io.FileNotFoundException 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77) 
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:52) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:194) 
    at com.acme.util.xml.XMLTestData.<init>(XMLTestData.groovy:33) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77) 
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:52) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:198) 
    at com.acme.rest.testing.RestTestCase.setUp(RestTestCase.groovy:67) 
    at com.acme.rest.testcases.waka.TagsPositivePathDRI.super$5$setUp(TagsPositivePathDRI.groovy) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) 
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1058) 
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:127) 
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:147) 
    at com.acme.rest.testcases.waka.TagsPositivePathDRI.setUp(TagsPositivePathDRI.groovy:27) 
    at junit.framework.TestCase.runBare(TestCase.java:132) 
    at junit.framework.TestResult$1.protect(TestResult.java:110) 
    at junit.framework.TestResult.runProtected(TestResult.java:128) 
    at junit.framework.TestResult.run(TestResult.java:113) 
    at junit.framework.TestCase.run(TestCase.java:124) 
    at junit.framework.TestSuite.runTest(TestSuite.java:243) 
    at junit.framework.TestSuite.run(TestSuite.java:238) 
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83) 
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:51) 
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:63) 
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    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:75) 
    at $Proxy3.processTestClass(Unknown Source) 
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:86) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    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.MethodInvocationUnmarshallingDispatch.dispatch(MethodInvocationUnmarshallingDispatch.java:48) 
    at org.gradle.messaging.dispatch.DiscardOnFailureDispatch.dispatch(DiscardOnFailureDispatch.java:31) 
    at org.gradle.messaging.dispatch.AsyncDispatch.dispatchMessages(AsyncDispatch.java:129) 
    at org.gradle.messaging.dispatch.AsyncDispatch.access$000(AsyncDispatch.java:33) 
    at org.gradle.messaging.dispatch.AsyncDispatch$1.run(AsyncDispatch.java:69) 
    at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:63) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:662) 

回答

1

這是非常依賴於如何TestConfig等類別查找XML文件,但是如果你想要的資源,以便在classpath中,你應該將它們放在項目/ src目錄/主/資源

1

既然你沒有指定這個,我會假設你使用的是常規插件,你有你的時髦人士在以下位置:

  • projectRoot/src/main/groovy - 對於常規的src文件
  • projectRoot/src/test/groovy - 對於常規測試的src文件

默認情況下,您可以爲您的主,你的測試類資源文件夾:

  • projectRoot/src/main/resources - 這是需要爲您的應用程序
  • projectRoot/src/test/resources資源 - 測試所需的資源

如果您沒有這些文件夾,請創建它們並將您的文件粘貼到projectRoot/src/test/resources。他們會自動被構建拾取。

0

你應該把這些XML文件放入文件夾的src/main /或資源的src /測試/資源 你並不需要將它們添加到的build.gradle或其他配置爲gradle這個

相關問題