Create a class called myClass that contains a static method, public static int simpleAdd(int x, int y). We all know how to add, so do something within the simpleAdd method to make it return the wrong sum of x + y.
We are now going to test our simple incorrect method by creating a new JUnit testcase in our Java project. Simply right click on your project -> New -> JUnit Testcase. Call it MyTest. From there it is fairly straightforward to get Eclipse to generate stubs for your test cases. If you get lost, visit http://www.vogella.de/articles/JUnit/article.html.
When writing the test cases, you will need to consult section section 4.4 of the link posted above to figure out what test methods you can use. To actually test our class, be sure to Run As -> Junit Test. You should get a red bar that indicates failure, but we know why the test failed. Now go back and make simpleAdd do the right thing. You should get a green bar indicating success.
Now that you are starting to get the hang of JUnit, you can go back and test your classes from the last two recitations to make sure that your code is 100% correct. If you write good test cases, then you can easily get 3 100's out of this!
If you do find an error in your code from your test case:
Show me it. Go back and fix the incorrect method. Show me the green bar and tell me what you did.
At the end of the recitation, resubmit any recitations that you corrected as well as MyClass.java & MyTest.java
