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:

  1. Make a directory for this lab.
  2. Setup your development environment.
  3. 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.
  1. Edit the SectionComparator class.
  2. Compile the SectionComparator class.
  3. What errors did the compiler find? How did you fix them?

  4. Edit the SectionComparatorDriver class.
  5. Compile and execute the SectionComparatorDriver.
  6. Which test cases failed?

  7. bMean and oMean are initialized incorrectly. Fix these faults.
  8. What changes did you make?

  9. Compile and execute the SectionComparatorDriver.
  10. Which test cases failed?

  11. result is initialized incorrectly. Fix this fault.
  12. What changes did you make?

  13. Compile and execute the SectionComparatorDriver.
  14. Which test cases failed?

  15. Edit the Statistics class.
  16. There is a fault in the Statistics.min(int[]) method. Specifically, result is initialized incorrectly. Fix this fault by initializing result to data[0].
  17. Compile the Statistics class and execute the SectionComparatorDriver.
  18. Which test cases failed?

  19. What kind of test case is clearly missing?

  20. 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.

  21. Compile and execute the SectionComparatorDriver class.
  22. What should the result of test case D be and what is it?

  23. It is now impossible to know whether this failure is a result of faults in the Statistics class or faults in the SectionComparatorDriver class.
  24. Test the Statistics.max(int[]) method.
  25. What test cases did you use?

  26. What fault(s) did you discover and how did you fix them?

  27. Compile and execute the SectionComparatorDriver class.
  28. 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.
  1. In spite of the fact that the SectionComparator now appears to work, there is a fault in the Statistics.mean(int[]) method.
  2. Test the Statistics.mean(int[]) method.
  3. What test cases did you use?

  4. 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.
  1. Test the Statistics.mean(int[]) method.
  2. What test cases did you use?

  3. What fault(s) did you discover and how did you fix them?

  4. Test the Statistics.max(int, int) method.
  5. What test cases did you use?

  6. What fault(s) did you discover and how did you fix them?

  7. Test the Statistics.min(int, int) method.
  8. What test cases did you use?

  9. What fault(s) did you discover and how did you fix them?

  10. Test the Statistics.sign(double) method.
  11. What test cases did you use?

  12. What fault(s) did you discover and how did you fix them?

Copyright 2010