Spring 2026 — Assignment 2
Due 9-February-2026, 11am EST (before class)
Purpose:
- Practice static analysis
- Apply RIPR model to design tests
- Understand testability, controllability, and observability
- Recognize characteristics of good test cases
- Practice test automation framework — JUnit
All homeworks are due before class on the due date.
All homework assignments must reflect your own understanding of the topic
and be communicated in your own words.
You may use one of the
collaborative options.
You may also request help and advice from your classmates on Piazza.
Any help not allowed by that policy will be an honor violation.
Early-submission bonus points
Purpose: To encourage students to start working on the homework assignments early
and recognize students who are actively engaged in the content
You will receive
- 4% of the points you earn (from the assignment)
if you submit your assignment at least 48 hours early (submitted by 7-February-2026 11am EST).
- 2% of the points you earn (from the assignment)
if you submit your assignment at least 24 hours early (submitted after 7-February-2026 11am EST,
by 8-February-2026 11am EST).
Note:
The final submission timestamp shown on Gradescope will be used.
[Total: 20 points]
Part 1: JUnit tests for CountWords (8 points)
Consider CountWords.java.
- Analyze and design tests for the Count method.
You should practice and apply the RIPR model when designing tests.
- Automate all tests you designed using JUnit
- Run your tests and take a screenshot (or screenshots) showing the test results.
- If the tests fail, analyze and briefly describe/discuss what causes the failure(s).
Although we do not expect you to satisfy any specific test criterion,
at a minimum, your tests must reach every line of code in the method.
Grading rubric:
- (4 points) The quality of the tests you designed
- Tests are properly designed
- Tests have clear purposes
- Input values are reasonable (w.r.t the domain application)
- Proper input values and correct expected output (given the input values)
- A set of tests you designed reach every line of code in the method.
- (4 points) Your JUnit tests
Reminder: do not modify the program under test
Part 2: JUnit Data-Driven Tests for Cal (8 points)
Consider Cal.java.
Apply RIPR model to design tests,
develop JUnit data-driven tests for the cal() method.
—
the cal() method only.
Do not develop tests for the main() and getN() methods.
Since there is a precondition excluding basically all invalid inputs,
you should test normal behavior only.
- You are required to develop JUnit data-driven tests.
- No points will be awarded for non-data-driven tests.
- Run your tests and take a screenshot showing the test results.
- If the tests fail, analyze and briefly describe/discuss what causes the failure(s).
Although we do not expect you to satisfy any specific test criterion,
at a minimum, your tests must reach every line of code in the method.
Grading rubric:
- (4 points) The quality of the tests you designed
- Tests are properly designed
- Tests have clear purposes
- Input values are reasonable (w.r.t the domain application)
- Proper input values and correct expected output (given the input values)
- A set of tests you designed reach every line of code in the method.
- (4 points) Your JUnit tests
Reminder: do not modify the program under test
Part 3: Analyze and fix a test flaw (4 points)
The Java method removeDuplicates() is supposed to
remove all duplicate strings in the object.
The following JUnit test method for removeDuplicates()
has a flaw that is non-syntactic
(that is, assume this test compiles and runs to completion).
In the test method, words is an instance of an object
that stores strings in the order they are added and has methods
add(), removeDuplicates(),
getFirst(), getNext(),
isFirst(), and isNext(),
which do exactly what you would expect from their names. For example,
If words = "cookie cake cake pie"
removeDuplicates() removes the second "cake" from words
Thus, words = "cookie cake pie"
You can assume that the words variable has been properly instantiated,
and the add(), getFirst(), getNext(),
isFirst(), and isNext() methods have already been tested.
@Test
public void testRemoveDuplicates()
{
words.add("cookie");
words.add("cake");
words.add("cake");
words.add("pie");
words.removeDuplicates();
assertTrue(words.getFirst().equals("cookie"));
}
- (2 points) Identify the flaw of the testRemoveDuplicates method
and describe it in terms of the RIPR model.
Be as precise, specific, and concise as you can.
For full credit, you must use the terminology introduced in this course.
- (2 points) Explain how you would fix the test method.
You may assume other methods are available on the object.
You may rewrite the testRemoveDuplicates method
or explain what the fix would be.
What to submit:
- Part 1:
- Your JUnit test file (.java). Do not submit .class file
We will download and run your JUnit tests.
- (-8 points) if your JUnit test file (.java) is missing or inaccessible,
does not open, does not compile, or does not run.
Thus, be sure to verify that your JUnit .java file is accessible, compiles, and runs.
- A brief report including evidence that your JUnit tests ran,
the results of running your tests, and
a discussion of any tests that failed (The first two may be screenshots).
- (-1 point) if no evidence showing the run and the results is provided
- Part 2:
- Your JUnit test file (.java). Do not submit .class file
We will download and run your JUnit tests.
- (-8 points) if your JUnit test file (.java) is missing or inaccessible,
does not open, does not compile, or does not run.
Thus, be sure to verify that your JUnit .java file is accessible, compiles, and runs.
- A brief report including evidence that your JUnit tests ran,
the results of running your tests, and
a discussion of any tests that failed (The first two may be screenshots).
- (-1 point) if no evidence showing the run and the results is provided
- Part 3:
- Written solutions to the questions
- If you collaborated, submit a brief collaboration summary: all partner names
(refer to the collaborative options)
and a summary of what each contributed.
( -5 points) for 24 hours late (submitted after 9-February 11am EST, by 10-February 11am EST)
(-10 points) for 48 hours late (submitted after 10-February 11am EST, by 11-February 11am EST)
(-2 points) for submitting a Word document or handwriting, or a write-up that is not a typed PDF file.
Submission
- Your report as a PDF file. Only typed PDF—No handwriting. No hand-drawing. No Word document.
- Your JUnit test files (.java)
- JUnit test file for CountWords.java
- JUnit test file for Cal.java
Upload your report as a PDF to Assignment2 on Gradescope.
Make sure you connect your partner to your group on Gradescope so that everyone receives credit.
Each team submits only one copy.
Making your submission available to instructor and course staff is your
responsibility;
if we cannot access or open your file, you will not get credit.
Be sure to test access to your file before the due date.
Copyright © 2026 Upsorn Praphamontripong
Released under the
CC-BY-NC-SA 4.0 license.
Last updated 2026-02-01 18:24