在Eclipse中使用Ant运行JUnit测试时出现问题.初学者问题 [英] problem running JUnit tests with Ant in Eclipse. Beginner question
问题描述
这些天,我正在学习如何使用蚂蚁按照以下教程.
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>
当我将其运行到日食中时,出现以下错误:
When i run it into eclipse I get the following error:
[javac] C:\ Documents和 设置\ 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的路径指定为classpath属性,嵌套元素或对在其他地方声明的路径的引用.
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屋!