Two Laptop Bag*
The moose likes Beginning Java and the fly likes Some problems with testing with JUnit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Some problems with testing with JUnit" Watch "Some problems with testing with JUnit" New topic
Author

Some problems with testing with JUnit

shreehari Gopalakrishnan
Ranch Hand

Joined: Jun 01, 2004
Posts: 30
I am new to JUnit
I have unzipped the JUnit files to D:\junit3.8.1 and my junit.jar is in that location

There are mainly 2 problems
Problem 1
**********

I have set the class path correctly to D:\junit3.8.1\JUnit.jar

But when i am compiling

java junit.jar junit.swingui.TestRunner [File]
It is showing No Class Def Found error

When i compile like this it is working

java -cp junit.jar junit.swingui.TestRunner [File]

why like this ?

Problem 2
*********

When i complile my Test case file

import junit.framework.TestCase;
public class TestMyProg extends TestCase
{
public void testmyFunction()
{
MyProg mp = new MyProg();
int actual = mp.myFunc();
int exp = 2;
assertEquals("mp.myFunc()",exp,actual);
}
}

It is showing errors

TestMyProg.java:1: cannot resolve symbol
symbol : class TestCase
location: package framework
import junit.framework.TestCase;
^
TestMyProg.java:2: cannot resolve symbol
symbol : class TestCase
location: class TestMyProg
public class TestMyProg extends TestCase
^
TestMyProg.java:9: cannot resolve symbol
symbol : method assertEquals (java.lang.String,int,int)
location: class TestMyProg
assertEquals("mp.myFunc()",exp,actual);
^

Why is like that what i have to do ? an early reply prefered

Thanks in advance
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by shreehari Gopalakrishnan:
But when i am compiling

java junit.jar junit.swingui.TestRunner [File]
It is showing No Class Def Found error

When i compile like this it is working

java -cp junit.jar junit.swingui.TestRunner [File]

That's not how you compile Java classes. java is the command you execute Java code, javac is the command with which you compile Java code.

Originally posted by shreehari Gopalakrishnan:
TestMyProg.java:1: cannot resolve symbol
symbol : class TestCase
location: package framework
import junit.framework.TestCase;
^
TestMyProg.java:2: cannot resolve symbol
symbol : class TestCase
location: class TestMyProg
public class TestMyProg extends TestCase
^
TestMyProg.java:9: cannot resolve symbol
symbol : method assertEquals (java.lang.String,int,int)
location: class TestMyProg
assertEquals("mp.myFunc()",exp,actual);
^

All of these compilation errors are due to the compiler not finding junit.jar from your classpath. Could you post the command with which you're compiling?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Since this is not a JUnit problem per se but a general Java question, I'm moving this topic over to the "Java in General" forum. Please continue the discussion over there.
shreehari Gopalakrishnan
Ranch Hand

Joined: Jun 01, 2004
Posts: 30
Sorry Lasse
What i meant was Running not compiling for the first problem

For compiling i have given Javac File name

so i got these errors can i please suggest?
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Originally posted by shreehari Gopalakrishnan:
Sorry Lasse
What i meant was Running not compiling for the first problem

For compiling i have given Javac File name

so i got these errors can i please suggest?


javac is not finding the junit.jar.
Are you compiling in windows env? If so in your dos window type

echo %classpath%

Does it show the classpath that you have set (including junit.jar)?

If you are on unix platform, type

set grep |CLASSPATH

or

echo $CLASSPATH


If all else fails, compile the testcase using the -cp argument (-cp d:/...).


Ever Existing, Ever Conscious, Ever-new Bliss
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Some problems with testing with JUnit
 
Similar Threads
thread not running on my comp...plz help
junit test using eclips IDE
Junit Compilation errors
package junit.framework does not exist
error: package junit.framework does not exist