Java Reference
In-Depth Information
public static double convertInchestoFeet(double inches){
return inches / 12;
}
public static double convertCmtoFeet(double cm){
return convertMeterstoFeet(cm / 100);
}
public static double convertFeettoCm(double feet){
return convertFeettoMeters(feet) * 100;
}
public static double convertCmtoInches(double cm){
return convertFeettoInches(convertCmtoFeet(cm));
}
public static double convertInchestoCm(double inches){
return convertFeettoCm(convertInchestoFeet(inches));
}
4.
Now create a JUnit test case by rightâclicking on the
DistanceConverter.java
file in the
Navigator. Select New, then JUnit Test Case. The name should be
DistanceConverterTest
and
the class under test field should be
chapter6.DistanceConverter
(
chapter6
is the package
name; it may be different if you have used another package). You do not need any auto method
stubs checked. Some of these fields may be filled in for you.
5.
Click Next. If you place a check next to
DistanceConverter
, test method stubs will be created for
all methods in the class. Click Finish.
6.
Now you should have created a new testing class that looks like this:
import static org.junit.Assert.*;
import org.junit.Test;
public class DistanceConverterTest {
@Test
public void testConvertFeettoMeters() {
fail("Not yet implemented");
}
@Test
public void testConvertMeterstoFeet() {
fail("Not yet implemented");
}
@Test
public void testConvertFeettoInches() {
fail("Not yet implemented");
}
@Test
public void testConvertInchestoFeet() {
Search WWH ::
Custom Search