2012-05-16 81 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