【问题标题】:ant-cannot find symbol@Testant-找不到符号@Test
【发布时间】:2013-10-29 07:21:59
【问题描述】:

我正在尝试编译以下只有一个函数的类。

公共类 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 编译成功,但是编译失败

【问题讨论】:

    标签: selenium ant junit


    【解决方案1】:

    您可能需要将 jUnit 库添加到类路径以便 Ant 知道它在哪里?

    ...
    <classpath path="path/to/your/junit.jar"/>
    ...
    

    【讨论】:

    • @Shabeer 你也可以看看这个模板:github.com/mplacona/java-junit-template-project
    • 感谢您将 junit.jar 路径放入类路径中。谢谢。
    • 我遇到了另一个问题。我正在尝试在我的脚本中使用 IEDriver,但是当我在 ant 中编译时出现错误:错误:包 org.openqa.selenium.ie 不存在。请问我该如何解决这个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多