2012-05-16 43 views
1

我对Ant很陌生,昨天写了一个简单的build.xml。然而,在查看运行ant -verbose的输出后,看起来好像一个类我不得不处理许多JUnit测试。Ant任务参数的顺序

<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测试是在测试类,我需要与

java org.junit.runner.JUnitCore Tests 

但是基于以下的输出,我相信它被称为运行类作为

java Tests org.junit.runner.JUnitCore 

Ant -verbose输出:

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调用。谢谢!

+0

考虑使用http://ant.apache.org/manual/Tasks/junit.html – Vadzim

回答

0

您已将您的论点(即Tests)与主要类别org.junit.runner.JUnitCore相互转换。

<arg>是程序 <jvmarg>的论点的JVM

的论点在他们两人之间,你将有主类。

的Java用法:

用法:JAVA [-options]类[参数...]

在你的情况,你要执行的org.junit.runner.JUnitCore的主要方法和传递的参数到主要的方法应该是Tests

+0

Ooooooh,我明白了,谢谢! – Chris