我是第一次接触ANT和JUnit。根据需求,我在Eclipse中创建了'JUnitTestCase‘,并根据适当的注释调用所请求的测试类。当通过'Ant Build‘运行'build.xml’文件时,它抛出如下错误:
D:\ecllipse\eclipse\JunitTestProject>ant compile
Buildfile: D:\ecllipse\eclipse\JunitTestProject\build.xml
setClassPath:
init:
clean:
compile:
[echo] making directory...
[echo] classpath------:
[echo] compiling...
[javac] Compiling 4 source files to D:\ecllipse\eclipse\JunitTestProject\build
[javac] D:\ecllipse\eclipse\JunitTestProject\src\jnuittestPckg\HelloWorldTest.java:3: package org.junit does not exist
[javac] import org.junit.After;
[javac] ^
[javac] D:\ecllipse\eclipse\JunitTestProject\src\jnuittestPckg\HelloWorldTes
t.java:4: package org.junit does not exist
[javac] import org.junit.Before;
[javac] ^ 在回顾JUnitTEstCase时,我已经导入了(import org.junit.After;import org.junit.Before和import org.junit.Test;)这样的注释。我还为'junit.jar‘设置了构建路径。我试了很多,但还是想不通。我还将JUnitTest项目附加为:
package jnuittestPckg;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;公共类HelloWorldTest {
private HelloWorld硬件;
@Before
public void setUp() throws Exception {
hlwrd = new HelloWorld();
System.out.println("I am in Before");
}
@After
public void tearDown() throws Exception {
System.out.println("I am in After");
}
@Test
public void testClass1() {
hlwrd.Class1(null);
}
@Test
public void testClass2() {
hlwrd.Class2(null);
}}
请帮帮我。
发布于 2012-07-10 13:25:21
您的test.classpath属性不包含junit.jar。将它添加到类路径中,这个问题就会得到解决。
https://stackoverflow.com/questions/11394865
复制相似问题