Reputation: 19
Okay, I am trying to test a class with a test class using import junit.framework.*;
and I download the Junit library and saved it with a classpath of:C:\Program Files (x86)\Java\jdk1.7.0_07\lib\junit-4.8.2.j…
I set up the CLASSPATH, and every time I try to compile the test file I get this error:
C:\Users\Anita\Documents\java\Project2>j… TestImage.java
TestImage.java:1: error: package junit.framework does not exist
import junit.framework.*;
^
Did I do something wrong in the classpath
? I tried everything! Any suggestions on how I can finally get junit to work?
Upvotes: 1
Views: 1058
Reputation: 3038
...A couple of years late...
At least in 2014, you need to import
from org.junit
. The JUnit "Getting Started" guide states "Do not use any classes in junit.framework or junit.extensions."
As an example:
import org.junit.*;
public class TestFoobar {
@BeforeClass
public static void setUpClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@Test
public void testSomething() {
}
@Test
@Ignore
public void thisIsIgnored() {
}
@After
public void tearDown() throws Exception {
// Code executed after each test
}
@AfterClass
public static void tearDownClass() throws Exception {
}
}
...and then run tests
C:\junit>dir
Volume in drive C is L032336
Volume Serial Number is CAB2-E609
Directory of C:\junit
2014-10-20 06:57 <DIR> .
2014-10-20 06:57 <DIR> ..
2014-10-20 06:11 45,024 hamcrest-core-1.3.jar
2014-10-20 06:11 245,039 junit-4.11.jar
2014-10-20 06:57 518 TestFoobar.java
3 File(s) 290,581 bytes
2 Dir(s) 277,498,945,536 bytes free
C:\junit>javac -cp junit-4.11.jar TestFoobar.java
C:\junit>java -cp .;junit-4.11.jar;hamcrest-core-1.3.jar org.junit.runner.JUnitCore TestFoobar
JUnit version 4.11
I.
Time: 0.007
OK (1 test)
Upvotes: 1
Reputation: 2508
Try to unzip your jar to check if the contents is really there. Also, instead setting the environment variable, try to pass the classpath as an argument, like follows:
javac -cp ./junit-4.8.2.jar TestImage.java
but instead of ./junit-4.8.2.jar
, use the full path of your jar.
Upvotes: 1