Guide to Object-oriented Programming With Java (University at Buffalo Version)
Chapter 13: JUnit Testing and Using the Debug Tool
Testing an Application Using Junit
Before you can write any unit tests you need to create the application to be tested. For example,
Creating the Junit Test Template
Use the following steps to create a template Junit test for your
Adding Test Cases
Now you are ready to add some test cases to the
DistanceConverterTest.java file to produce the following window.
Note: the above example has a test failure because the test case for
convertFeettoMeters() is testing for feet to be a 2 but we
assert (expects) it to be a 1.
Using the Eclipse Debug Tool
Eclipse has a built-in debug tool that provides a way to walk through your code and observe values for your variables and objects. You can set breakpoints so that when you run your code Eclipse will stop at the next breakpoint. This is a handly tool to determine if your variables have a value that you expect them to have and to help figure out why you may be getting unexpected results.