Java Reference
In-Depth Information
figure 6-18  
testing programs with JUnit test Cases 
try it out
In this exercise, you develop a JUnit test case for a small program. This will show you how you can use
JUnit testing to ensure your programs are operating as intended.
1. If you do not already have a project in Eclipse for Chapter 6, create one now.
2. Create a new class by right‐clicking on the src folder in your new project. Select New and then
Class. Name the class DistanceConverter . Uncheck the box that creates the main method for
you. Click Finish to create the class.
3. Include the following methods in the body of the DistanceConverter class. Notice that there is no
main method in this class. Therefore, it is not possible to test the methods simply by running the
program.
public static double convertFeettoMeters(double feet){
return feet * 0.3048;
}
public static double convertMeterstoFeet(double meters){
return meters * 3.2808;
}
public static double convertFeettoInches(double feet){
return feet * 12;
}
Search WWH ::




Custom Search