我是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 -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 :(得分:0)
您已中断了您的参数(Tests
)和主要类org.junit.runner.JUnitCore
。
<arg>
是该计划的参数
<jvmarg>
是JVM的参数
在他们两人之间,你将拥有主要的班级。
Java用法:
用法:java [-options] class [args ...]
在您的情况下,您想要执行org.junit.runner.JUnitCore
的main方法,并且传递给该main方法的参数应为Tests