Results 1 to 3 of 3
  1. #1
    phil128 is offline Member
    Join Date
    Sep 2008
    Posts
    40
    Rep Power
    0

    Default Junit. Pulling my HAIR OUT!

    Hello. I've downloaded the latest JUNIT and i'm trying to get it to work with eclipse. Currently i've got a basic class and a test class. The problem i'm having is when i try and run it i get the following error:

    Java Code:
    java.lang.NoClassDefFoundError: org/junit/runner/notification/RunListener
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    Here is my main class:

    Java Code:
    public class rectangle {
    
    	/**
    	 * @param args
    	 */
    	
    	private double width;
    	private double height;
    	
    	
    	public rectangle(double width, double height)
    	{
    		this.width = width;
    		this.height = height;
    	}
    	
    	public double getWidth()
    	{
    		return width;
    	}
    	
    	public double getHeight()
    	{
    		return height;
    	}
    	
    	public void setWidth(double width)
    	{
    		this.width = width;
    	}
    	
    	public void setHeight(double height)
    	{
    		this.height = height;
    	}
    	
    	public double getArea()
    	{
    		return width * height;
    	}
    	
    	public double getDiagonalLength()
    	{
    		return Math.sqrt(width*width + height*height);
    	}
    	
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		rectangle rec = new rectangle(2,3);
    		
    	}
    
    
    }
    My test Class

    Java Code:
    import static org.junit.Assert.*;
    
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    
    
    public class rectangleTest {
    
    	@Before
    	public void setUp() throws Exception {
    	}
    
    	@After
    	public void tearDown() throws Exception {
    	}
    
    	@Test
    	public void testGetWidth() {
    		fail("Not yet implemented");
    	}
    
    	@Test
    	public void testGetHeight() {
    		fail("Not yet implemented");
    	}
    
    }
    I've imported junit via the preferencies->ant->runtime. And still i have no luck.

    Could somebody please help me. Pleeeeeeeeease

    The test case was the pre-generated test case. But i've tried it with a difference set of test cases and i still have the same error.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    Quote Originally Posted by phil128 View Post
    I've imported junit via the preferencies->ant->runtime. And still i have no luck.
    Mhm, try the following:
    Project -> Properties -> Java Build Path

    -> Add Library -> JUnit, or
    -> Add External Jars

  3. #3
    phil128 is offline Member
    Join Date
    Sep 2008
    Posts
    40
    Rep Power
    0

    Default

    -> Add Library -> JUnit, or
    -> Add External Jars

    Worked. Thanks alot! Heck none of the lectures at uni told us about that.

    Works a treat

Similar Threads

  1. Pulling from an Active Directory
    By Sno in forum New To Java
    Replies: 1
    Last Post: 09-24-2010, 09:15 PM
  2. JUnit
    By cka in forum Eclipse
    Replies: 3
    Last Post: 07-27-2010, 04:14 PM
  3. Junit on Jar Files
    By mecrazycoder in forum NetBeans
    Replies: 0
    Last Post: 07-01-2009, 11:12 AM
  4. Junit
    By Azndaddy in forum New To Java
    Replies: 6
    Last Post: 06-15-2008, 06:47 AM
  5. TRying to use jUnit for Tesing
    By sandor in forum New To Java
    Replies: 3
    Last Post: 04-18-2007, 11:17 PM

Posting Permissions

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