Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Some problems with testing with JUnit

 
shreehari Gopalakrishnan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 382
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:/...).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic