Reputation: 11
I'm writing my build.xml. However, it seems there is something go wrong with my junit task. when I run my junit task. I can build success, but the junit report only show that run 1 test with error. But I have more than 10 tests. So I wonder if there is something run with my junit task. Here is my code.
<property name="src.dir" value="src"/>
<property name="bin.dir" value="bin"/>
<property name="dest.dir" value="dest"/>
<property name="test.dir" value="test/>
<property name="lib.dir" value="lib"/>
<path id="classpath">
<pathelement location="${lib.dir}/junit-4.11.jar"/>
<pathelement location="${lib.dir}/ant-junit4.jar"/>
</path>
<target name="test" depends="compile">
<junit printsummary="yes" haltonfailure="no">
<classpath>
<pathelement location="${bin.dir}"/>
<path refid="classpath"/>
</classpath>
<formatter type="plain" usefile="false"/>
<batchtest fork="yes">
<fileset dir="${test.dir}" includes="*Test*.java"/>
</batchtest>
</junit>
</target>
I cannot figure out what is wrong so could somebody help me out?
Upvotes: 0
Views: 243
Reputation: 107040
And what is happening? Do you get any error messages?
You usually need to do the following:
*.class
files should be placed inside a directory such as target/classes
or build/classes
. Use the destdir
parameter of the <javac>
task to do this.destdir
where your normal classes were compiled to.target/test-classes
or build/test-classes
.Once you've compiled the JUnit tests, you may run them. You can use the <junit>
task like you did.
includeantruntime
parameter is set to true
fork
to true
.target/test-classes
or build/test-classes
. In your example, you're trying to run them against the source.I use the Maven standards for my directory layout. That means my Java source is under src/main/java
while my JUnit Java files are under src/test/java
. Any XML or properties or other none source files needed are stored in src/main/resources
. The regular source is compiled to target/classes
while the Junit sources are compiled to target/test-classes
.
This makes it easy to compile your code and test code separately without worrying about **/test/**
, **/Test/**
, **/JUnit/**
exceptions in directory compiling since everything is separate.
Hope this helps.
Upvotes: 1