I'm using the Test Context Framework to do integration testing, along with Mockito/Powermock for mocking. I have an Ant script that runs all my tests using the junit ant task. The script works, as long as I specify fork="true" for the junit task. I can also run all of my tests directly from Eclipse.
As I keep adding integration tests, to save time when executing the tests, I want to take advantage of the context caching that the test context framework supplies, and as such, I need to remove forking. However, when I do so, I get errors for each test, complaining of FileNotFound exceptions when looking for my application context files. The error message is: java.io.FileNotFoundException: class path resource [com/docfinity/test/context/common-test-context.xml] cannot be opened because it does not exist. Again, the only change is turning fork="false".
I should note that I'm using inheritance to define multiple -context.xml files.
Here is the Ant script excerpt:
This is the error that I get:Code:<?xml version="1.0" encoding="UTF-8"?> <project name="tests" default="test"> <description> Run all unit tests </description> <property name="baseDir" value="./.." /> <property name="reportDir" value="${baseDir}/core/build/reports" /> <target name="test"> <delete dir="${reportDir}" /> <mkdir dir="${reportDir}"/> <junit haltonfailure="false" haltonerror="false" failureproperty="fail" errorproperty="error" fork="true"> <classpath> <pathelement location="${baseDir}/api/build/classes"/> <pathelement location="${baseDir}/core/build/classes"/> <pathelement location="${baseDir}/web/build/classes"/> <fileset dir="${baseDir}/dependencies/libraries/compile"> <include name="**/*.jar"/> </fileset> <fileset dir="${baseDir}/dependencies/libraries/compile_only"> <include name="**/*.jar"/> </fileset> <fileset dir="${baseDir}/dependencies/libraries/test"> <include name="**/*.jar"/> </fileset> <fileset dir="${baseDir}/dependencies/libraries/runtime"> <include name="**/*.jar"/> </fileset> </classpath> <formatter type="xml"/> <formatter type="brief" usefile="false"/> <batchtest todir="${reportDir}"> <fileset dir="${baseDir}/api/build/classes"> <include name="**/*Test.class"/> <include name="**/*Tests.class"/> </fileset> <fileset dir="${baseDir}/core/build/classes"> <include name="**/*Test.class"/> <include name="**/*Tests.class"/> </fileset> <fileset dir="${baseDir}/web/build/classes"> <include name="**/*Test.class"/> <include name="**/*Tests.class"/> </fileset> </batchtest> </junit> <junitreport todir="${reportDir}"> <fileset dir="${reportDir}"> <include name="TEST-*.xml"/> </fileset> <report todir="${reportDir}"/> </junitreport> <fail if="fail" message="At least one test failed, see test reports for details."/> <fail if="error" message="At least one test errored, see test reports for details."/> <delete dir="${baseDir}/build" /> </target> </project>
This error repeats for every test suite that I run. Why does forking the JVM cause the files to go missing from the classpath?Code:[junit] Testcase: test(com.docfinity.auditing.dto.DocumentHistoryAssemblerTests): Caused an ERROR [junit] Failed to load ApplicationContext [junit] java.lang.IllegalStateException: Failed to load ApplicationContext [junit] at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308) [junit] at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) [junit] at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) [junit] at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:333) [junit] at com.docfinity.test.CommonTestBase.setUp(CommonTestBase.java:136) [junit] at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:309) [junit] at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:112) [junit] at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:73) [junit] at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:297) [junit] at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:222) [junit] at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:161) [junit] at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:135) [junit] at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:133) [junit] at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:112) [junit] at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:55) [junit] at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32) [junit] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423) [junit] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137) [junit] Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [com/docfinity/test/context/common-test-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [com/docfinity/test/context/common-test-context.xml] cannot be opened because it does not exist [junit] at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341) [junit] at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) [junit] at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) [junit] at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) [junit] at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) [junit] at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212) [junit] at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:81) [junit] at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1) [junit] at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280) [junit] at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304) [junit] Caused by: java.io.FileNotFoundException: class path resource [com/docfinity/test/context/common-test-context.xml] cannot be opened because it does not exist [junit] at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158) [junit] at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)


Reply With Quote
