Making jUnit output info and compile to /build folder
I have the following Ant buildfile:
<?xml version="1.0"?>
<!-- the value of the default attr must be one of the targets. -->
<project name="Money" default="build-source" basedir=".">
<description>The Money project build file.</description>
<property name="src" location="."/>
<property name="build" location="build"/>
<property name="junit" location="lib/junit-4.9b3.jar"/>
<path id="_classpath">
<pathelement path="${junit}"/>
<pathelement path="${build}"/>
</path>
<target name="prepare">
<mkdir dir="${build}"/>
</target>
<target name="build-source" depends="prepare"
description="compile the source ">
<javac srcdir="${src}" destdir="${build}">
<classpath refid="_classpath"/>
</javac>
</target>
<target name="run" depends="build-source">
<junit printsummary="on" showoutput="on">
<test name="money.MoneyTest"/>
<classpath refid="_classpath"/>
</junit>
</target>
</project>
It's pretty basic - I'm just trying to get this thing to run properly. What I don't get is: 1) Why does it output the comp开发者_如何学JAVAiled files to a /build/money directory? I want the output directory to be just /build, given this directory structure for my files:
build/
build.xml
lib/
src/
test/
2) When there are tests that don't pass, it says "Test money.MoneyTest FAILED". I'd like it to output info about the failure, expected / actual values, line number, etc.
I can't figure this out by staring at the buildfile above. Any advice?
It outputs the compiled files under
build
, creating a directory structure that corresponds to the layout of your packages.Since you put your classes in the
money
package, the output will be underbuild/money
. If you put your classes under aorg.example.foo
package, your output would be in thebuild/org/example/foo
directory.To have your
.class
files inbuild
, you would have to use the default package.Edit I assume your source files have a
package money;
declaration, as in:package money; public class MoneyTest { ... }
If you add a
<formatter>
element, detailed reports about test failures will be written to an output file (by default, named TEST-name). See also the Ant Junit Task Documentation.<junit printsummary="withOutAndErr" showoutput="on"> <formatter type="plain"/> <test name="money.MoneyTest"/> <classpath refid="_classpath"/> </junit>
I have not found a way to directly print the failed tests reports to standard output.
精彩评论