开发者

Running an JUnit test as Ant target

开发者 https://www.devze.com 2023-01-11 13:34 出处:网络
I\'ve got a simple test case in /build directory that I\'m trying to compile and run with Ant. Compilation is fine, but I can\'t figure out how to run this. The class is:

I've got a simple test case in /build directory that I'm trying to compile and run with Ant. Compilation is fine, but I can't figure out how to run this. The class is:

package money;

import org.junit.*;
import static org.junit.Assert.*;

public class MoneyTest {

    @Test
    public void testAmount() {
        Money m = new Money(20);
        System.out.println("AMOUNT: " + m.amount());
        System.out.println("DOUBLE AMOUNT: " + m.doubleAmount());
        assertEquals(21, m.amount());
    }

}

and the buildfile goes like this:

<?xml version="1.0"?>
<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.8.2.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">
        <java classname="${build}/MoneyTest">
            <classpath refid="_classpath"/>
        </java>
    </target>

</project>

when I run "ant run" from the Terminal, it says that it cannot find the class at that path.

Thanks beforehand!


You've specified a location as a classname. The name of the class would be money.MoneyTest, not /home/build/money/MoneyTest.

However, you should be using the junit task instead of the java task anyway, given that it's a JUnit test rather than a Java app itself. (It doesn't have a main method, for example.)

0

精彩评论

暂无评论...
验证码 换一张
取 消