0

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");
	}

}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by peter_budo
0

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));
  }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.