Lab: Experimenting with Testing (Part II)
Instructions:
Answer as many of the following questions as you can during the lab period.
If you are unable to complete the assignment during the lab period it
is strongly recommended that you complete it on your own.
Getting Ready:
Before going any further, you should:
-
Make a directory for this lab.
-
Setup your development environment.
-
Download the following files:
to your working directory. (In most browsers, the easiest
way to do this is by right-clicking on each of the links above.)
1. The Stages of Testing: This part of the lab will help
you understand the benefit of performing unit testing before
integration testing.
-
Edit the
SectionComparator
class.
-
Compile the
SectionComparator
class.
-
What errors did the compiler find? How did you fix them?
-
Edit the
SectionComparatorDriver
class.
-
Compile and execute the
SectionComparatorDriver
.
-
Which test cases failed?
-
bMean
and oMean
are initialized
incorrectly. Fix these faults.
-
What changes did you make?
-
Compile and execute the
SectionComparatorDriver
.
-
Which test cases failed?
-
result
is initialized
incorrectly. Fix this fault.
-
What changes did you make?
-
Compile and execute the
SectionComparatorDriver
.
-
Which test cases failed?
-
Edit the
Statistics
class.
-
There is a fault in the
Statistics.min(int[])
method.
Specifically, result
is initialized incorrectly.
Fix this fault by initializing result
to
data[0]
.
-
Compile the
Statistics
class and execute the
SectionComparatorDriver
.
-
Which test cases failed?
-
What kind of test case is clearly missing?
-
Add the following initializations to
the
SectionComparatorDriver
:
int[] bD = {50, 60, 70};
int[] oD = {70, 60, 50};
and add code that uses this test case.
-
Compile and execute the
SectionComparatorDriver
class.
-
What should the result of test case D be and what is it?
-
It is now impossible to know whether this failure is a result
of faults in the
Statistics
class or
faults in the SectionComparatorDriver
class.
-
Test the
Statistics.max(int[])
method.
-
What test cases did you use?
-
What fault(s) did you discover and how did you fix them?
-
Compile and execute the
SectionComparatorDriver
class.
-
Are there any failures?
2. The Importance of Unit Testing: This part of the lab
will help you understand why you need to complete all unit tests
before moving to integration testing.
-
In spite of the fact that the
SectionComparator
now
appears to work, there is a fault in the
Statistics.mean(int[])
method.
-
Test the
Statistics.mean(int[])
method.
-
What test cases did you use?
-
What fault(s) did you discover and how did you fix them?
3. Additional Practice:
This part of the lab is optional;
complete it on your own if you think you need more practice with
testing.
-
Test the
Statistics.mean(int[])
method.
-
What test cases did you use?
-
What fault(s) did you discover and how did you fix them?
-
Test the
Statistics.max(int, int)
method.
-
What test cases did you use?
-
What fault(s) did you discover and how did you fix them?
-
Test the
Statistics.min(int, int)
method.
-
What test cases did you use?
-
What fault(s) did you discover and how did you fix them?
-
Test the
Statistics.sign(double)
method.
-
What test cases did you use?
-
What fault(s) did you discover and how did you fix them?