The high-level goals of this exercise are to (1) learn about systematic unit testing and (2) reason about test quality, using code coverage criteria.
Team up in groups of size 2.
Assign yourself to the correct (In-class2-Coverage) group on Canvas. (If you are in a Canvas group of size 1, you can still submit.)
Make sure Apache Ant, a Java 8 or 11 or 17 JDK, and Git are installed. (The set-up tips for Ant may be useful.) The required software is already installed on attu.cs.washington.edu, if you prefer to do the exercise there.
Clone the following git repository and read its README.md
file: https://bitbucket.org/rjust/coverage
Test your set up: compile and test the Triangle program.
Familiarize yourself with the triangle program (src/triangle/Triangle.java).
Familiarize yourself with the example test suite (test/triangle/TriangleTest.java).
Run ant coverage
and then inspect the coverage report it generates: coverage_results/index.html. If you are running on attu, see the attu_coverage guide.
Develop 4 test suites (i.e., add tests to the testTable
method in TriangleTest.java
) that satisfy the following coverage criteria:
You may reuse tests between test suites. For each test suite, make a commit and tag it (i.e., git commit
followed by git tag
; use SC, DC, CC, and MCDC as tag names).
Skip the dummy test (i.e., add an @Ignore
annotation to the testDummy method) and regenerate the coverage report. (Note the difference in the coverage report, which is related to question 1 below.)
Cobertura instruments the Java byte code for measuring code coverage.
For the purpose of measuring code coverage, state two advantages for instrumenting source code and two advantages for instrumenting Java byte code or an intermediate representation more generally.
Which instrumentation approach is preferable? Briefly explain why?
Which coverage criterion does Cobertura’s branch coverage correspond to? Why?
Give a definition of “test redundancy”, using a code coverage criterion and provide an example of a redundant test for one of your test suites (explicitly state which existing test in your test suite is redundant with the example you provide). Given your definition of test redundancy, would you remove redundant tests from an existing test suite? Briefly explain why or why not.
Consider the following two, functionally equivalent code snippets (a, b, and c are boolean inputs):
Version 1
o1 = (a | b) & c
Version 2
t1 = a | b
o2 = t1 & c
Provide a minimum MCDC-adequate test suite for each Version.
For each of the two test suites, is it MCDC-adequate for the other version?
Can you create two MCDC-adequate test suites of equal size – one being adequate for Version 1 and one being adequate for Version 2 but not Version 1?
Summarize your observations from the three prompts above (4a–4c) and briefly discuss guarantees and/or implications w.r.t. adequacy and code structure.
A plain-text file (or PDF) with your answers to the four questions above. Please list all group members.
An archive (zip) of your git repository (compressed .git folder), which contains the four tagged commits for your developed test suites.
One team member should upload the deliverables to Canvas, via the Canvas submission site for this course.
ant clean test
to make sure that your added tests pass before computing coverage.