SWE 437 Assignment 4
Spring 2018

Due 19-February, beginning of class

Intellectuals solve problems; geniuses prevent them. —Albert Einstein

Answer the following questions. All homeworks are due before class on the due date. Please remember that the GMU Honor Code is in effect: You may use one of the collaborative options as specified on the syllabus. You may also request help and advice from your classmates on Piazza. Any other help not allowed by that policy will be an honor violation. Bring hardcopies of your answers to class; either hand written or printouts.

  1. (12 points) JUnit testing for quotes
    1. (8 points) Create and run JUnit tests for the method search() in the class QuoteList.java. Your tests must reach every return statement in the method (at least four tests). Submit, on paper, printouts of your tests and a screen shot showing that they ran.
    2. (2 points) Which part of each test addresses observability?
    3. (2 points) Which part of each test addresses controllability?

  2. (8 points) JUnit test flaw

    The Java method removeDuplicates() is designed to remove all duplicate strings in the object. (Clarification 15-February: removeDuplicates() should retain the first instance, and remove subsequent duplicate instances of the string.)

    The following JUnit test method for removeDuplicates() has a flaw that is not syntactic. That is, assume this test compiles and runs to completion.

    In the test method, words is an instance of an object that stores strings in the order they are added. words has methods add(), removeDuplicates(), and getFirst(), which do exactly what you would expect from their names. You can assume that words has been properly instantiated and the add() and getFirst() methods have already been tested.

    public void testRemoveDuplicates()
       words.add ("cookie");
       words.add ("cake");
       words.add ("cake");
       words.add ("pie");
       assertTrue ("removeDuplicates method", words.getFirst().equals ("cookie"));
    1. (4 points) Describe the flaw in terms of the RIPR model. Be as precise, specific, and concise as you can. For full credit, you must use the terminology introduced in the book.
    2. (4 points) Rewrite the test method to correct the flaw.