I apologize ahead as I'm very new to software testing. But I have what looks like a simple code to create a White-box test cases with 100% code coverage:
01 public class ShapeAreas {
02
03 public double oneParameter(String shape, float x1)
04 {
05 float area;
06 if (shape.equals("A"))
07 return x1 * x1 * Math.XI;
08 else if (shape.equals("B"))
09 return x1 * x1;
10 else
11 return -1.0;
12 }
13
14 public double twoParameter(String shape, float x1, float x2)
15 {
16 float area;
17 if (shape.equals("N"))
18 return x1 * x2;
19 else if (shape.equals("M"))
20 return 0.5 * x1 * x2;
21 else
22 return -1.0;
23 }
24 }
I need help on what my input data should look like on this code to achieve 100% code coverage with the least number of test cases.
I appreciate any help I can get on this, thanks!
You have to look for the branches in each of the methods to get 100% coverage. It's
A,B,Xasshapeparameter for theoneParametermethod andN,M,Xfor thetwoParametermethod.3 test cases for each method would give you 100% coverage.
However, it will not tell you that your code is 100% correct.
Try e.g.
nullas shape. (Which would result in aNullpointerException)You would also need to define the precision required for your calculations. (
doublereturn type vs. float calculations.)