CS314: Assignment A3
White box testing

Assigned: Sep 18, 2014
Due: Sep 25, 2014
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 CodeCover Eclipse plugin.

How to install

  1. Go to Help -> Install New Software...
  2. Click on Add...
  3. Enter location: http://update.codecover.org/ name : CodeCover Update Site and click ok.
  4. After clicking it will take some time to CodeCover 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. Enable Code Cover to project.
    1. Select the project for A2.
    2. Right click and select Properties -> select CodeCover
    3. check Enable CodeCover and all the bellow options. click ok.
  2. Select classes
    • Right click on class (eg. World.java and Coordinate.java) and select "Use For Coverage Measurement"
  3. Run unit tests with CodeCover
    • Right click on test class (eg. TestAll.java) select Run As -> Code cover Measurement For JUnit. This will run all your JUnit tests with codecover.
  4. View Results
    1. Goto Test Sessions and check your test result.
    2. Goto Window (in top menu) -> Show View -> Other ...
    3. Select Coverage. This will show your results.
  5. Generate report.
    1. Download code cover plugin from here (http://downloads.sourceforge.net/codecover/codecover-batch-1.0.tar.bz2) and extract it.
    2. Goto Export -> Coverage Result Export
    3. Select the session, select type as Report and select a file name.
    4. For template select HTML.Report_hierarchic.xml from your extracted folder.
    5. Print the report for submission.
Note that the coverage report should show the data for statement coverage and branch coverage after you ran all the tests (i.e., a cumulative report) for each of the methods in World and Coordinate, as well as the each class as a whole.

(10 points) Print 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 Ramct.