Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main

Python
C++
JAVA
PHP
SQL
Alice

TestingClock


Description

JUnit Testing Exercise

In this exercise you will write some tests for the ClockModel class in the Clocks Project.
  1. Get the Clocks project from GIT (following the same technique you have used previously). The URL is https://bitbucket.org/ferzle/clocks.
  2. Add a class ClockTests to the tests package:
    1. Right-click on the test package and select New-->JUnit Test Case.
    2. Make sure that New JUnit 4 test is selected
    3. Put ClockTests in for the Name.
    4. Click the Browse... button next to Class under test:.
    5. Start typing ClockModel in the box near the top until it shows up on the list below.
    6. Double click ClockModel.
    7. Click Next.
    8. Put check marks next to the two constructors, setTime, incrementSeconds and incrementMinutes. (Since time is limited you will only write tests for some of the methods. We can add as many tests as we want later. All this step does is add empty methods for us.)
    9. Click Finish.
    10. If it asks about adding JUnit 4 to the build path, make sure Perform the following action is checked and that under that it says Add JUnit 4 library to the build path and click OK.
    11. It should have created your class and opened it in the editor.
  3. Implement the tests you just created. Proceed as follows.
    1. setTime. This one is pretty easy. These tests will assume that the various getters are correct, which seems somewhat reasonable.
    2. IncrementMinutes. Make sure to test the increment methods in at least two cases: when the number increments to something less than 60 and when it increments to 60.
    3. IncrementSeconds. This needs as least three different sorts of test cases, one "normal" case and two different "exceptional" cases.
    4. Constructors. The default constructor might be a little tricky to get exactly right.