mercredi 31 décembre 2014

Ant build class files with TestNG using textiles

I am using Ant to build my project and am encountering a problem dealing with running my tests with text files when I use TestNG. Below is my code that contains two targets that compile and run my test code:



<target name="compile-tests" depends="compile"
description="Compile the project test source-code." >

<mkdir dir="${testBuildDir}" />

<javac destdir="${testBuildDir}" classpathref="test.path"
debug="${java.debug}" optimize="${java.opt}" deprecation="on">
<src path="${testSrcDir}" />
</javac>

<!-- Copies text testing files over -->
<copy todir="${testBuildDir}">
<fileset dir="${testSrcDir}">
<include name="**/*.txt" />
</fileset>
</copy>
</target>

<target name="test" depends="compile-tests"
description="Runs all the unit tests">
<testng suitename="boggle-tests" outputdir="${testResultsDir}">
<classpath>
<path refid="test.path" />
<pathelement path="${testBuildDir}" />
</classpath>
<classfileset dir="${testBuildDir}" />
</testng>
</target>


Also, I have provided below a list of properties used in my xml file:



<property name="srcDir" location="src" />
<property name="libDir" location="lib" />

<property name="buildDir" location="build"/>
<property name="buildClassesDir" location="${buildDir}/classes"/>
<property name="javaDocDir" location="${buildDir}/javadoc"/>

<property name="testSrcDir" location="test"/>
<property name="testBuildDir" location="${buildDir}/tests"/>
<property name="testResultsDir" location="${buildDir}/results"/>

<property name="testNGFile" location="${libDir}/testng-6.8.jar" />


So I have contained my testing source code and my testing text files used by the source code in the ${testBuildDir}. My compile-tests target simply compiles the .java files and creates .class files in the destination as well as copying my testing .txt files.


Then my test target just runs all these .class files using the TestNG framework. The problem I am having is that when I run the test target, my test code fails because it says that it could not find the .txt files used for testing purposes. However, I don't understand why this happens since my compile-tests target clearly works as expected and includes the .txt test files.


I have been struggling on this for too long and really need so help.


Aucun commentaire:

Enregistrer un commentaire