JMU
Lab: Experimenting with Testing (Part I)


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. Black-Box Testing: This part of the lab will help you get seome experience with black-box testing.
  1. The Calculator class contains the following two methods:
        /**
         * Calculates the inverse of a number
         *
         * @param x   The number
         * @return    The inverse (i.e., 1.0/x)
         */
        public static double inverse(double x)
    
    
        /**
         * Calculates the percentage that a part is of a whole
         * (assuming both are non-negative)
         * 
         * @param part  The part (i.e., numerator)
         * @param whole The whole (i.e., denominator)
         * @return      A percentage (where 100.0 = 100%)
         */
        public static double percent(double part, double whole)
        

    Make sure you understand the purpose of these two methods.

  2. Write a driver that can be used to test the inverse() method.
  3. What code did you write?
  4. Compile and execute your driver.
  5. What values (if any) caused inverse() to fail?
  6. Write a driver that can be used to test the percent() method.
  7. What code did you write?
  8. Compile and execute your driver.
  9. What values (if any) caused percent() to fail?
  10. What symptom made you realize that percent() method failed?
  11. Can you test for this symptom in Java? (Don't guess; add code to your driver and see.)
2. Clear-Box Testing: This part of the lab will help you gain experience with clear-box testing and desk checking.
  1. Open the Series class.
  2. Desk check the arithmetic() method.
  3. What errors (if any) did you find?
  4. What oracle could you use to test the arithmetic() method? (Note: An oracle is a component that can be used to verify the function of another component.)
  5. Write a driver that tests the arithmetic() method using this oracle.
  6. Did you detect any failures?
  7. Desk check and/or test the pi(int) method.
  8. Correct the fault(s) you detected (if any).
  9. What failures did you find and what faults did you correct?
3. Clear-Box Testing of Subclasses: This part of the lab will help you understand some of the issues that arise when testing subclasses.
  1. Open the Document and FormattedDocument classes and refresh your memory of them. (You used them in the lab on "Experimenting with Accessibility/Visibility".)
  2. Which class should you test first? Why?
  3. Within the Document class, which method should you test first, getDescription() or getWordCount()? Why?
  4. Describe six important test cases for the getWordCount() method.
  5. Within the FormattedDocument class, in what order should you test the various methods?
  6. Do you need to test the inherited methods?
  7. When is it especially important to test inherited methods?
  8. Describe five additional (over and above those you identified for the getWordCount() method) important test cases for the getText() method.

Copyright 2011