Activity 01
Test-First Challenge: Write Tests Before the Code
Give pairs the specification for a class (e.g., a Temperature converter with specific conversion methods and edge case behavior) but not the implementation. Pairs write unit tests first, then implement the class to make those tests pass. Debrief on what the exercise revealed about the specification's ambiguities.
Explain the purpose and benefits of unit testing in software development.
Facilitation TipDuring Test-First Challenge, ask students to swap their written tests with a partner before coding the class, forcing them to verify that test expectations are clear and feasible.
What to look forPresent students with a simple Java class (e.g., a `Calculator` with `add` and `subtract` methods). Ask them to write two JUnit tests for the `add` method: one for positive numbers and one for a positive and a negative number. Check if they correctly implement the Arrange-Act-Assert pattern.