This is much more to our liking. And JUnit also gives us a better error message when a test fails. If we, for example, changes the "72" in the last line above to "71", JUnit will give this message:

There was 1 failure:
1) testSomething(hansen.playground.TestCourse)
junit.framework.AssertionFailedError:
expected:<71> but was:<72>

So now we also automatically get the calculated value of the expression "c.parUpToHole(18)".

JUnit offers a lot of features, but in the following examples I'll show the most common and simple among them. If you are interested in digging into the many options of JUnit www.junit.org contains links to several articles.

In order to make use of JUnit's features we must of course be prepared to follow a set of rules. Briefly these are:

Put your tests in a class that extends the JUnit-class "TestCase".

If your test cases use some common data then set it up in a method called "setUp".

Place the testcode (e.g. calls to"assertEquals") in one or more methods having names starting with "test".