Results 1 to 12 of 12
- 07-21-2010, 04:17 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 11
- Rep Power
- 0
JUnit - Test class not found in selected project
Hi,
I'm trying to write JUnit test but
I'm having trouble with the following errors:
"Test class not found in selected project" -> when running AClassTest.java
"Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class" -> when running AClass.java
I have class AClass.java
and class AClassTest.java
They both are in the same package and there is JUnit library
Here's the code:
AClass.java:
AClassTest.java:Java Code:public class AClass { working code is in the last post }
Java Code:public class AClassTest extends TestCase { working code is in the last post }Last edited by cka; 07-22-2010 at 12:03 PM.
- 07-21-2010, 04:41 PM #2
Is this an IDE question or a java programming question or what?
What program outputs the errors?
If java programming, can you show the command line you are using to execute the program and the full text of the errors you get.
- 07-21-2010, 05:00 PM #3
Member
- Join Date
- Jul 2010
- Posts
- 11
- Rep Power
- 0
I'm not sure if the problem is with IDE or with my coding.
I considered posting it on the eclipse subforum.
I'm using eclipse.
When I run AClass.java I get this in the console: "Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class"
When I run AClassTest.java which is JUnit testclass I get this:
[the error shows when I click on warning]

except that there is no other messages
this is where the classes are [if it is of any help]:
Last edited by cka; 07-21-2010 at 05:04 PM.
- 07-21-2010, 05:03 PM #4
That's an IDE problem. Try asking it on a forum for your IDE.
- 07-21-2010, 05:31 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
What version of JUnit are you using?
Ah, I see the JUnit3 folder...
I'm pretty certain you're supposed to pass the "name" into the super constructor...that "name" paarmeter is (I think) a test name (ie the name of one of your test methods) when used by the Test Suite stuff that JUnit runs. So passing "hhjj" in will fail since you don't have a testhhjj() method.Java Code:public AClassTest(String name) { super("hhjj"); }
- 07-21-2010, 11:43 PM #6
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
As far as I know from Junit testing but it has been awhile doesn't all methods have to begin with the word.....test???
e.g.
maybe I am wrong it has been awhileJava Code:public int testMySum{ }
- 07-22-2010, 08:45 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Might have still been the case with JUnit 3 (in fact I think it was), but with JUnit 4 you use an annotation to identify a method as a test.
- 07-22-2010, 10:20 AM #8
Member
- Join Date
- Jul 2010
- Posts
- 11
- Rep Power
- 0
@Tolls
"hhjj" is there coz i've been changing it to see if it matters but whatever I put there the result is the same.
So I've had:
and as you suggested:Java Code:public AClassTest(String name) {super(name);}
Java Code:public AClassTest(String name) {super("GetPower");}@al_Marshy_1981Java Code:public AClassTest(String name) {super("testGetPower");}
but my testing method does begin with the word test
I have put the AClass.java in a new project just to see what happens (there is no JUnit, not testing class, just AClass.java) but I still got an error:
"Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class"
I don't get it. I'm not testing anything.
Now I have discovered that whatever I try to run it gives me that error... even the classes in a different project that I know are working because I've tested them earlier..Last edited by cka; 07-22-2010 at 10:29 AM.
- 07-22-2010, 11:18 AM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Sorry, the first one (super(name)) was actually my suggestion, but I can see it wasn't entirely clear.
:)
That's what goes in the constructor.
Why are you focussing on the AClass class? You run the AClassTest class, not the class you are testing.
- 07-22-2010, 11:58 AM #10
Member
- Join Date
- Jul 2010
- Posts
- 11
- Rep Power
- 0
I concentrated on it coz when I tried to run any other class I got the same error. So, I got little scared coz I didn't know what's going on and when I tried to google the problem I couldn't find anything on it.
But I see what I was doing wrong.
It's working now.
I switched to JUnit 4 and as you've said I concentrated too much on the AClass.
Thanks for help
Below is an example for anyone else using JUnit for the first time and who is being as silly as me:
ZClass.java
ZClassTest.javaJava Code:package ZPackage; public class ZClass { public double z; public double v; public double k; public double u; public ZClass(double z, double v, double k) { this.z=z; this.v=v; this.k=k; } public double getPower(double f) { u = (v+k); double Sf = (z+v+k+u+f); return Sf; } }
Java Code:package TestZPackage; import junit.framework.TestCase; import org.junit.After; import org.junit.Before; import org.junit.Test; import ZPackage.ZClass; public class ZClassTest extends TestCase { private ZClass zclass; @Before protected void setUp() throws Exception { super.setUp(); } @After protected void tearDown() throws Exception { super.tearDown(); } public ZClassTest(String arg0) { super(arg0); zclass = new ZClass(3.0,2.0,1.0); } @Test public final void testGetPower() { assertEquals(zclass.getPower(2.0), 11.0); } }
- 07-22-2010, 12:29 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
I do find 4 a lot easier to use, but I'm still curious why 3 wasn't working...oh well, at least it works now.
- 07-27-2010, 04:08 PM #12
Member
- Join Date
- Jul 2010
- Posts
- 11
- Rep Power
- 0
Norm said that the topic is an IDE problem so I've put it to eclipse subforum.
For those who are interested:
JUnit
Similar Threads
-
junit test problem
By moamen in forum EclipseReplies: 2Last Post: 03-14-2010, 09:41 PM -
Help please! .class expected when compiling JUnit test?
By tfitz666 in forum New To JavaReplies: 2Last Post: 12-31-2009, 12:45 PM -
JUnit Test??? What is it all about????? Please help!!
By nikosa in forum New To JavaReplies: 1Last Post: 08-03-2009, 05:31 PM -
JUnit Test Help!
By pharo in forum New To JavaReplies: 0Last Post: 04-10-2009, 05:15 PM -
Junit test
By alice in forum New To JavaReplies: 1Last Post: 06-14-2008, 01:24 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks