0

I am new to ANT and JUnit. As per the requirement i created 'JUnitTestCase' in Eclipse and call the requested test classes as per proper annotation. While running the 'build.xml' file through 'Ant Build', it throws error as:

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]                     ^  

While looking back to JUnitTEstCase, i have imported the annotations like (import org.junit.After;import org.junit.Before and import org.junit.Test;). I, also, set build path for 'junit.jar'. I tried lot but couldn't figure it out. i am also attaching JUnitTest project as:

package jnuittestPckg;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class HelloWorldTest {
private HelloWorld hlwrd;

@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);
}

}

Please help me out.

4

1 回答 1

0

You test.classpath property does not include the junit.jar. Add it to the classpath and this issue will be resolved.

于 2012-07-10T05:25:20.623 回答