I am running my test from java junit test files. Its getting file fine from test folder of my project. like ABCTest is my project. inside this project I have test/testfiles folder and there is some .xlsx file. When I am getting run my test code from java class from eclipse like Run As-> Junit test , Its can read file from this folder.
fileNameWithPath="test/testfiles/abc.xlsx"
out = new ByteArrayOutputStream();
fis = new FileInputStream(fileNameWithPath);
bis = new BufferedInputStream(fis);
while ((c = bis.read()) != -1) {
out.write(c);
}
fileData = out.toByteArray();
But for same code If I am going to run Java Test file from ant script its getting error
<target name="prepare" depends="resolve">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.test.classes.dir}" />
<mkdir dir="${build.test.reports.dir}" />
<path id="test.cp">
<fileset dir="${lib.test.dir}">
<include name="junit-4.8.2.jar" />
<include name="dozer-*.jar" />
</fileset>
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
<fileset dir="${lib.apache.dir}">
<include name="*.jar" />
</fileset>
</path>
</target>
<target name="tests.compile" depends="prepare">
<javac destdir="${build.test.classes.dir}" excludes="/backend/security/**/*.*" debug="true" optimize="true" deprecation="false" failonerror="true">
<src path="${src.test.dir}" />
<src path="${src.dir}" />
<classpath>
<path refid="test.cp" />
</classpath>
</javac>
<copy file="test/src/dozer.properties" todir="${build.test.classes.dir}" />
<copy file="test/src/test.log4j.properties" todir="${build.test.classes.dir}" />
<copy todir="${build.test.classes.dir}/testApplicationContexts">
<fileset dir="${src.test.dir}/testApplicationContexts" />
</copy>
<copy todir="${build.test.classes.dir}/test/testfiles">
<fileset dir="${basedir}/test/testfiles" />
</copy>
</target>
<target name="tests.run" depends="tests.compile">
<junit fork="yes" forkmode="once" haltonfailure="no" showoutput="no" printsummary="yes" maxmemory="256m">
<jvmarg value="-Dlog4j.configuration=test.log4j.properties"/>
<formatter type="xml" />
<classpath>
<pathelement location="${build.test.classes.dir}" />
<path refid="test.cp" />
</classpath>
<batchtest todir="${build.test.reports.dir}">
<fileset dir="${src.test.dir}">
<include name="**/FileReadTest.java" />
</fileset>
</batchtest>
</junit>
I am not getting actual reason for this.
NB : I am using spring MVC. and Junit test for this. Project is build with ant.
Exception like this
java.io.FileNotFoundException: test\testfiles\abc.xlsx (The system cannot find the path specified)