I am new to JUnit testing.
For example, I have a Misc class in a project:
public class Misc{
public static int computeValue(int x,int y,int z)
{
int value = 0;
if((x==y)||(z==0))
value = x+2;
else if(x>y)
value = y+4;
else
value = z;
return value;
}
}
I gave it a try in the JUnit class but I'm not too sure if I have done it correctly.
public class MiscTest {
@Test
public void testXEqualToY() {
//Only X is equal to Y and z is not zero
int x = 5,y=5;
int value = 0;
value = Misc.computeValue(5, 5, 10);
assertEquals("test error",x,y,value);
}
@Test
public void testZEqualZero(){
//Only z is 0
int x=4,y=8,z=0;
int value = 0;
value = Misc.computeValue(11,5,0);
assertEquals("test error",z,value);
}
What should I put in the test case methods to test the values?
getValue. If you knew what function it is supposed to do, you could test whether it does it without worrying about individual statements. I often write interface documentation and unit tests in parallel. Writing the tests brings out holes in the documentation. Writing the documentation calls attention to things that should be tested.