So I'm suppose to create a JUnit test for 3 classes... each method should have its own test case... I've created the test classes, but I don't know how to code the actual tests. Here's one class that I have to create a test for, and the test class I created.

public class Sphere {
	
	public double sphereVolume(double r){
		double sphereVol = (4.0 / 3.0) * Math.PI * (Math.pow(r, 3));
		return sphereVol;
	}
	
	public double sphereSurface(double r){
		double sphereSurArea = 4.0 * Math.PI * (Math.pow(r, 2));
		return sphereSurArea;		
		}
}

import junit.framework.TestCase;

public class SphereTest extends TestCase {

	public void testSphereVolume() {
		fail("Not yet implemented");
	}

}

import junit.framework.TestCase;

public class SphereTest2 extends TestCase {

	public void testSphereSurface() {
		fail("Not yet implemented");
	}

}

Any specific reason you want to use JUnit 3 instead of JUnit 4?

As for JUnit 4 test can be simple as

public class SphereTest{
  @Test
  public void testSphereVolume(){
    assertEquals(33.5 , new Sphere().sphereVolume(5));
  }

  @Test
  public void testSphereSurface(){
    assertEquals(53.5 , new Sphere().sphereSurface(5));
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.