CS314: Assignment A3
White box testing

Assigned: Sep 25, 2015
Due: Oct 2, 2015
50 points

This assignment has two parts:

  1. Using a white-box coverage measurement tool for Java programs.
  2. Drawing control flow graphs for a program.

Part a. Coverage Tool for Java (20 points)

Use the code from your previous JUnit assignment (A2). Recall that there were five classes, World, Coordinate, WorldTest, CoordinateTest, and TestAll. Measure code coverage of your own test cases using the EclEmma Eclipse plugin.

How to install

  1. Go to Help -> Install New Software...
  2. Click on Add...
  3. Enter location: http://update.eclemma.org/ name : EclEmma Update Site and click ok.
  4. After clicking it will take some time to EclEmma plugin appear in the text box.
  5. Click Select All and then Next.
  6. Click next, accept license agreement and client Finish. Ignore the security warning and restart eclipse.

How to use

  1. Select the project for A2.
  2. At the top where you have the Play buttons for running programs, click on the down-arrow next to the play button that has a red and green rectangle on the bottom-left of the play button.
  3. You can run the project as JUnit or as Java Application.
  4. You should be able to view Coverage in the view Console. You can expand the package in the console and view coverage for individual files. If you run multiple times as you add test cases, you can view new coverage by selecting the sessions from a dropdown menu (the one with gears).
  5. You can also right click on the project for A2, and select Properties. Click on Coverage to see a summary of various types of coverage.
  6. The code view will show colors indicating which parts of the code are covered (or not).
    • green for fully covered lines
    • yellow for partly covered lines
    • red for lines that have not been executed at all

(10 points) Copy the coverage numbers as part of the report.

(10 points) If any of your coverage numbers is less than 100%, write new test cases and increase the coverage to 100%. All the numbers must be 100% after you have added your test cases. Add the test cases to your report. If your coverage is already 100%, you automatically get the 10 points. If you feel that a certain part of the code is unreachable, provide an explanation in your report. Points will be deducted if the explanation is incorrect.

Part b. Control flow graph. (30 points)

We have provided code for performing binary search. The problem specification is as follows:

The following (possibly buggy) code implements the above problem.

    /* Code for binary search program */
    int binSearch(int[] A, int target) {
        int low = 0;
        int high = A.length-1;
        while (low <= high) {
            int middle = low + (high - low)/2;
            if (target < A[middle])
                high = middle - 1;
            else if (target > A[middle])
                low = middle + 1;
                return middle;
        return -1;

Tasks for part b:

  1. Draw the control-flow graph of this code inside the binSearch method. Label each node with statement numbers and clearly indicate the statements corresponding to each node. (10 points)
  2. Write test inputs that give 100% node coverage. For each test input, show which nodes are being covered. (10 points)
  3. Write test inputs that give 100% edge coverage. For each test input, show which edges are being covered. (10 points)

Turnin instructions

Print your answers and hand them as a single stapled report at the beginning of class. DO NOT turn in handwritten assignments; type your answers. Do not submit the assignment using Canvas.