Results 1 to 12 of 12
  1. #1
    cka
    cka is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default 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:
    Java Code:
    public class AClass {
    	working code is in the last post		
    }
    AClassTest.java:
    Java Code:
    public class AClassTest extends TestCase {
    	working code is in the last post
    }
    Last edited by cka; 07-22-2010 at 01:03 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    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.

  3. #3
    cka
    cka is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    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 06:04 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    That's an IDE problem. Try asking it on a forum for your IDE.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    What version of JUnit are you using?

    Ah, I see the JUnit3 folder...
    Java Code:
    	public AClassTest(String name) {
    		super("hhjj");
    	}
    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.

  6. #6
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    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.

    Java Code:
    public int testMySum{
    
    }
    maybe I am wrong it has been awhile

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    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.

  8. #8
    cka
    cka is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    @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:
    Java Code:
    public AClassTest(String name) {super(name);}
    and as you suggested:
    Java Code:
    public AClassTest(String name) {super("GetPower");}
    Java Code:
    public AClassTest(String name) {super("testGetPower");}
    @al_Marshy_1981
    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 11:29 AM.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    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.

  10. #10
    cka
    cka is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    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
    Java 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;
    	}		
    }
    ZClassTest.java
    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);
    	}
    
    }

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    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.

  12. #12
    cka
    cka is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    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

  1. junit test problem
    By moamen in forum Eclipse
    Replies: 2
    Last Post: 03-14-2010, 10:41 PM
  2. Replies: 2
    Last Post: 12-31-2009, 01:45 PM
  3. Replies: 1
    Last Post: 08-03-2009, 06:31 PM
  4. JUnit Test Help!
    By pharo in forum New To Java
    Replies: 0
    Last Post: 04-10-2009, 06:15 PM
  5. Junit test
    By alice in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 02:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •