This assignment has two parts:
- Using a white-box coverage measurement tool for Java programs.
- 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
- Go to Help -> Install New Software...
- Click on Add...
- Enter location: http://update.codecover.org/ name : CodeCover Update Site and click ok.
- After clicking it will take some time to CodeCover plugin appear in the text box.
- Click Select All and then Next.
- Click next, accept license agreement and client Finish. Ignore the security warning and restart eclipse.
How to use
- Enable Code Cover to project.
- Select the project for A2.
- Right click and select Properties -> select CodeCover
- check Enable CodeCover and all the bellow options. click ok.
- Select classes
- Right click on class (eg. World.java and Coordinate.java) and select "Use For Coverage Measurement"
- 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.
- View Results
- Goto Test Sessions and check your test result.
- Goto Window (in top menu) -> Show View -> Other ...
- Select Coverage. This will show your results.
- Generate report.
- Download code cover plugin from here (http://downloads.sourceforge.net/codecover/codecover-batch-1.0.tar.bz2) and extract it.
- Goto Export -> Coverage Result Export
- Select the session, select type as Report and select a file name.
- For template select HTML.Report_hierarchic.xml from your extracted folder.
- 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:
- Input: Array A[0..N-1] and number to be searched target.
- Output: The index of the number if found, or -1 if not found.
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;
else
return middle;
}
return -1;
}
Tasks for part b:
- 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)
- Write test inputs that give 100% node coverage. For each test input,
show which nodes are being covered.
(10 points)
- 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.