1

我是 Ant 新手,昨天在一些帮助下编写了一个简单的 build.xml。然而,在查看运行 ant -verbose 的输出之后,似乎我必须处理许多 JUnit 测试的类没有被适当地调用。

<project name="JUnit_tests" default="run" basedir=".">

<!-- Define variable properties -->
<property name="src" value="${basedir}"/>
<property name="junit" value="org.junit.runner.JUnitCore"/>

<!--<property name="junit" value="org.junit.runner.JUnitCore"/>-->

<!-- Appends all jars in the current directory to the classpath -->
<path id="compile.classpath">
    <fileset dir="./">
        <include name="*.jar"/>
    </fileset>
</path>

<!-- Compiles all code in the current directory and append to the classpath -->
<target name="compile">
    <javac destdir="${src}" srcdir="${src}">
        <classpath refid="compile.classpath"/>
    </javac>
</target>

<!-- Runs the Test code with junit argument as long as compile was run previously -->
<target name="run" depends="compile">
    <java classname="Tests" fork="true">
        <arg value="${junit}"/>
    </java>
</target>

我的 JUnit 测试在 Tests 类中,我需要使用

java org.junit.runner.JUnitCore Tests

但是基于以下输出,我相信它被称为

java Tests org.junit.runner.JUnitCore

Ant 详细输出:

run:
     [java] Executing '/usr/lib/jvm/java-6-sun-1.6.0.26/jre/bin/java' with arguments:
     [java] 'Tests'
     [java] 'org.junit.runner.JUnitCore'
     [java] 
     [java] The ' characters around the executable and arguments are
     [java] not part of the command.
     [java] Exception in thread "main" java.lang.NoSuchMethodError: main
     [java] Java Result: 1

有任何想法吗?我一直在做研究,但找不到太多关于参数顺序的信息,特别是使用 java 调用。谢谢!

4

1 回答 1

0

您已经颠倒了您的论点(即Tests)和主类org.junit.runner.JUnitCore

<arg>是程序 <jvmarg>的参数是JVM的参数

在他们两者之间,您将拥有主要课程。

Java用法:

用法:java [-options] 类 [args...]

在您的情况下,您要执行 main 方法,org.junit.runner.JUnitCore并且传递给该 main 方法的参数应该是Tests

于 2012-05-16T18:42:04.537 回答