Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

JUnit Testing Using Java ME JUnit Frameworks : Page 2

Just because Java Micro Edition lacks reflective capabilities doesn't mean Java Micro Edition developers miss out on the advantages of JUnit styled testing. JUnit-styled frameworks and tools can still improve ME application quality.


advertisement
A Simple Application
Before examining the various unit test frameworks, you will need some simple code to test. In this examination, the simple conversion classes below can be used to create and test Java ME unit tests.

public class DistanceConversion { public static int feetToMeters(int ft){ return (ft * 3048)/10000; } public static int metersToFeet(int meters){ return (meters*3281)/1000; } public static int milesToKM(int miles){ return (miles*1609)/1000; } public static int kmToMiles(int km){ return (km*6214)/10000; } } public class TemperatureConversion { public static float fahrenheitToCelsius (float degrees){ return ((degrees-32)/9)*5; } public static float celsiusToFahrenheit (float degrees){ return ((degrees * 9)/5)+32; } public static boolean isHotter (float degFaren, float degCel){ return ((fahrenheitToCelsius(degFaren))-degCel) > 0; } public static boolean isCooler (float degFaren, float degCel){ return ((fahrenheitToCelsius(degFaren))-degCel) < 0; } }

Note that this code uses CLDC 1.1's floating point primitive type. In order for this code to execute in a CLDC 1.0 environment, the code would need to use integer primitives in place of float primitives as shown below. A copy of all the code and test classes for both CLDC 1.1 and CLDC 1.0 is provided in zip files with this article.

public class DistanceConversion { public static int feetToMeters(int ft){ return (ft * 3048)/10000; } public static int metersToFeet(int meters){ return (meters*3281)/1000; } public static int milesToKM(int miles){ return (miles*1609)/1000; } public static int kmToMiles(int km){ return (km*6214)/10000; } } public class TemperatureConversion { public static int fahrenheitToCelsius (int degrees){ return ((degrees-32)/9)*5; } public static int celsiusToFahrenheit (int degrees){ return ((degrees * 9)/5)+32; } public static boolean isHotter (int degFaren, int degCel){ return ((fahrenheitToCelsius(degFaren))-degCel) > 0; } public static boolean isCooler (int degFaren, int degCel){ return ((fahrenheitToCelsius(degFaren))-degCel) < 0; } }





Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap