在 Eclipse 中使用 Ant 运行 JUnit 测试时出现问题.初学者问题 [英] problem running JUnit tests with Ant in Eclipse. Beginner question

查看:25
本文介绍了在 Eclipse 中使用 Ant 运行 JUnit 测试时出现问题.初学者问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些天我正在学习如何使用 ant 运行自动化测试,以下是教程.

I'm learning these days how to use ant to run automated test folowing this tutorial.

我的项目的类路径中有 JUnit.一切似乎都很好,我可以将它包含在我的课程中:

I have JUnit in the classpath of my project. All seem to work fine and I can include it in my classes:

import junit.framework.TestCase; //line20

public class SimpleLattice1DTest extends TestCase{
 ...
}

我的 build.xml 是:

My build.xml is:

<?xml version="1.0"?>
<project name="Ant-Test" default="compile" basedir=".">
    <!-- Sets variables which can later be used. -->
    <!-- The value of a property is accessed via ${} -->
    <property name="src.dir" location="." />
    <property name="build.dir" location="build" />
    <property name="dist.dir" location="dist" />
    <property name="docs.dir" location="docs" />
    <property name="test.dir" location="jlife/tests" />
    <property name="test.report.dir" location="test/report" />  

    <!-- Deletes the existing build, docs and dist directory-->
    <target name="clean">
        <delete dir="${build.dir}" />
        <delete dir="${docs.dir}" />
        <delete dir="${dist.dir}" />
    </target>

    <!-- Creates the  build, docs and dist directory-->
    <target name="makedir">
        <mkdir dir="${build.dir}" />
        <mkdir dir="${docs.dir}" />
        <mkdir dir="${dist.dir}" />

        <mkdir dir="${test.report.dir}" />


    </target>

    <!-- Compiles the java code (including the usage of library for JUnit -->
    <target name="compile" depends="clean, makedir">
        <javac srcdir="${src.dir}" destdir="${build.dir}">
        </javac>

    </target>

    <!-- Creates Javadoc -->
    <target name="docs" depends="compile">
        <javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
            <!-- Define which files / directory should get included, we include all -->
            <fileset dir="${src.dir}">
                <include name="**" />
            </fileset>
        </javadoc>
    </target>

    <!--Creates the deployable jar file  -->
    <target name="jar" depends="compile">
        <jar destfile="${dist.dir}\CoreTest.jar" basedir="${build.dir}">
            <manifest>
                <attribute name="Main-Test" value="test.CoreTest" />
            </manifest>
        </jar>
    </target>


    <!-- Run the JUnit Tests -->
        <!-- Output is XML, could also be plain-->
        <target name="junit" depends="compile">
            <junit printsummary="on" fork="true" haltonfailure="yes">

                <formatter type="xml" />
                <batchtest todir="${test.report.dir}">
                    <fileset dir="${src.dir}">
                        <include name="**/*Test*.java" />
                    </fileset>
                </batchtest>
            </junit>
        </target>

</project>

当我将它运行到 eclipse 时,出现以下错误:

When i run it into eclipse I get the following error:

[javac] C:\Documents 和Settings\noname\Documenti\JLife_git\JLife_git\JLife\src\jlife\tests\SimpleLattice1DTest.java:20:包 junit.framework 不存在[javac] import junit.framework.TestCase;

[javac] C:\Documents and Settings\noname\Documenti\JLife_git\JLife_git\JLife\src\jlife\tests\SimpleLattice1DTest.java:20: package junit.framework does not exist [javac] import junit.framework.TestCase;

我想它有问题,但我不知道.有人能给我指明正确的方向吗?

I suppose there's something wrong with it, but I have no idea. Could someone put me in the right direction?

推荐答案

你的 javac 目标除了源和目标目录之外没有指定任何东西——它没有添加任何类路径条目;您需要为相应的 JUnit jar 文件添加一个条目.有关更多详细信息,请参阅 javac 任务文档.您可能希望将 JUnit 的路径指定为类路径属性、嵌套元素或对在别处声明的路径的引用.

Your javac target doesn't specify anything apart from the source and target directory - it doesn't add any classpath entries; you'll need to add an entry for the appropriate JUnit jar file. See the javac task documentation for more details. You may want to specify the path to JUnit as a classpath attribute, a nested element, or a reference to a path declared elsewhere.

这篇关于在 Eclipse 中使用 Ant 运行 JUnit 测试时出现问题.初学者问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆