Question: 1 . ( 2 5 points ) Due to the use of polymorphism, to achieve a certain coverage of testing we need to try all

1.(25 points) Due to the use of polymorphism, to achieve a certain coverage
of testing we need to try all possible implementations of a function that was
overridden in subclasses. So, while providing some benefits, the use of
polymorphism makes coverage testing mor difficult.
Use an example with abstract class Shape and its subclasses Circle and
Rectangle all of which have method float area(). Assuming the size of List
shapes remains to be 2, what permutations of instances of Circle and
Rectangle we have to test for due to polymorphism to achieve 100% branch
coverage ?
...
List shapes = new ArrayList(2);
// list shapes is populated with any permutation of instances of Circle and/or Rectangle
// class dynamically, say, from a user interface
float sumOfAreas =0.0f;
for(Shape shape : shapes){
sumOfAreas += shape.area();
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!