我正在尝试编译下面只有一个函数的类。
公共类TestAnnotations {
@Test
public void testLogin(){
System.out.println("Testing Login");
}
当我将文件作为JUNIt运行时,它可以工作,但是当我尝试从build.xml运行该文件时,它给出了以下错误:找不到符号@Test。我确实在正确的位置有Junit.jar文件。这是我的build.xml脚本:
<property environment = "env"/>
<property name="ws.home" value="${basedir}" />
<property name="ws.jars" value="D:/Data/eclipse/workspace/SeleniumDemo/lib/oracle_junit/junit.jar"/>
<property name="test.dest" value="${ws.home}/build" />
<property name="test.src" value="${ws.home}/src" />
<property name="test.reportDir" value="C:/reports"/>
<path id="testcase.path">
<pathelement location="${test.dest}" />
<fileset dir="${ws.jars}">
<include name="*.jar" />
</fileset>
</path>
<target name="init">
<mkdir dir="build/classes" />
</target>
<target name="clean">
<delete dir="${test.dest}" />
</target>
<target name="compile" depends = "init, clean">
<delete includeemptydirs= "true" quiet="true">
<fileset dir = "${test.dest}" includes = "**/*"/>
</delete>
<mkdir dir = "${test.dest}"/>
<javac
debug = "true"
destdir = "${test.dest}"
includeantruntime = "false"
srcdir = "${test.src}"
target = "1.7"
classpath = "${test.classpath}"
>
</javac>
</target>
<target name="run">
<fileset dir="${test.dest}">
<include name="tests/TestAnnotations.class" />
</fileset>
</target>
ant成功构建项目但在编译时失败
答案 0 :(得分:2)
您可能需要将jUnit库添加到类路径中,以便Ant知道它在哪里?
...
<classpath path="path/to/your/junit.jar"/>
...