The problem is my input to the program is of integer data type and the output is of double data type.So,while writing parameterized JUnit test cases,assertEquals gets striked off automatically...showing 2 errors.
They are as follows:
-The method assertEquals(double, double) from the type Assert is deprecated
-The method findarea(int) in the type Circle is not applicable for the arguments (int,
double)
Here the method findarea is my method to find the area of the circle.
Here is my code.
package BasicTesting;
import java.io.*;
class Circle
{
public static void main(String args[])throws IOException {
BufferedReader ob = new BufferedReader(new InputStreamReader(System.in));
int radius ;
System.out.println("Enter the radius of circle.. ");
radius=Integer.parseInt(ob.readLine());
Circle a=new Circle();
double g=a.findarea(radius);
System.out.println(g);
}
public static double findarea(int radius){
double area;
double pi=3.14;
area = pi * radius * radius;
return area;
}
}
This is my test case
package BasicTesting;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class CircleTest {
public CircleTest(int input, double expected,double delta) {
super();
this.input = input;
this.expected = expected;
this.delta = delta;
}
Circle ob=new Circle();
private int input;
private double expected;
private double delta;
@Parameters
public static Iterable<Object[]> testConditions() {
return Arrays.asList(new Object[][] {{1,3.14d,-2.14d},{2,12.56d,-10.56}});
}
@Test
public void Circletest() {
assertEquals(expected,Circle.findarea(input));
}
}
When I tried to run the test case,it shows the following error: java.lang.AssertionError: Use assertEquals(expected, actual, delta) to compare floating-point numbers. Please help me to rewrite this JUnit test case.I have tried several times.Please help me out.Thanks in adavance!