In-class exercise Mutation-based testing: Instructions

High-level goal

The high-level goals of this exercise are to (1) learn about mutation testing and (2) reason about test-goal utility.

Set up

  1. Team up in groups of size 2.

  2. Assign yourself to the correct (in-class-3-testing) group on Canvas. (You may work and submit alone, but you must still self-assign to a group on Canvas!)

  3. 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.) Use a Unix environment or Git bash on Windows for this exercise. The required software is already installed on attu.cs.washington.edu, if you prefer to do the exercise there.

  4. Clone the following git repository and read its README.md file: https://bitbucket.org/rjust/mutation

  5. Test your set up: compile and test the Triangle program.

  6. Run mutation.sh (make sure that the script works as intended).

You may use an experimental IntelliJ plugin for this exercise. See the detailed instructions for more details.

Instructions

  1. Read the entire assignment and ask any clarifying questions that you might have.

  2. Run mutation.sh and note the number of covered and detected mutants (see Question 1 below). Note that Major (the mutation tool) refers to “detected mutants” as “killed mutants”.

  3. Add tests to testTable to satisfy mutation adequacy – that is, until your test suite detects all non-equivalent mutants:

    1. Select a live mutant (for which you have not proven equivalence) for analysis.

    2. Determine whether it is equivalent – that is, provide a test case or proof of equivalence (see Questions 2 and 3 below).

    3. Run mutation.sh and continue with step a.

    You may find the show_mutant.sh script useful for reasoning about a mutant.

    Note that you will likely observe certain patterns (i.e., similar mutants requiring similar tests) because of the systematic mutation of the source code – adding multiple tests at once may speed up your testing process. Likewise, some mutants are easier to resolve than others – triaging the set of live mutants and selecting mutants out of order may speed up your testing process.

    If you get stuck on a mutant, take notes, move on, and revisit unresolved mutants later.

  4. Disable (comment out) the assertEquals statement on line 45 in the testTriangle method and run ant coverage and mutation.sh. Note the code coverage ratio(s) and mutation score (see Question 4 below).

Questions

  1. How many mutants does the initial test suite (1) cover and (2) detect (result from step 1 in the instructions)?

  2. How many mutants are equivalent (to the original program)? Provide a proof for each equivalent mutant.

  3. Were any of the generated mutants unproductive? Briefly explain your answer.

  4. What changes in code coverage ratio and mutation score did you observe after disabling the assertEquals statement in the testTriangle method? What are the implications for using the code coverage ratio as an adequacy criterion?

Deliverables

  1. A plain-text file with your answers to the four questions above. Please list all group members.

  2. Your mutation-adequate TriangleTest.java test suite.

  3. Your <timestamp>.csv file, if you used the IntelliJ plugin.

Steps for turn-in

One team member should upload the deliverables to Canvas, via the Canvas submission site for this course.

Hints