Jmunit of unit test development under Java me

Source: Internet
Author: User
Tags reflection netbeans

The summary cannot say that Java Micro Edition developers cannot take advantage of the JUnit style test because the Java Micro Edition lacks the ability to reflect. In fact, the Java ME developer can still improve the development quality of the Java ME application with some other frameworks and tools with JUnit style. This series of articles (two) is to explore in detail the application of the two open source frameworks, J2meunit and Jmunit, in the Java Me Unit test development.

First, the introduction

Today, JUnit testing is becoming a fundamental part of most Java Standard Edition (SE) and Enterprise Edition (EE) application development-especially for those who actively support test-driven developers. The original Smalltalk framework of Kent Beck and Eric Gamma became so popular and successful that it was ported to many programming languages, including ADA (Aunit), C # (NUnit), Python (Pyunit), and even Fortran ( Funit). Java JUnit has proven to be the most successful in all unit test frameworks and has derived many JUnit "variants" (in various "extensions") that ultimately help implement unit testing in mainstream development from multithreaded Java applications to advanced enterprise Java applications.

However, using JUnit or finding a junit extension for Java Micro Edition development has always been a difficult task. Notice that the JUnit framework relies on the Java Reflection API. Because the reflection API is not yet supported in the Java ME environment, a typical JUnit tool that relies heavily on reflection does not yet help with Java me development. However, there are two Java ME JUnit extensions that are built specifically for device application developers. Notably, with the release of NetBeans and NetBeans Mobility 5.5, NetBeans and NetBeans mobility packs are planning to incorporate a Java ME JUnit-style framework. This new version of the IDE will add unit tests to your Java ME application in a more agile way.

This article will introduce you to the JUnit test by using the Java ME JUnit Framework, and you'll find out how to get these tools, how to test them and how to use them to build better quality software.

Second, get Java Me Unit Test framework

Today, there are two javame JUnit test frameworks available on the market, which are j2meunit and jmunit. Both projects are free downloadable open source frameworks that you can download from a sourceforge.net package file.

However, the engineering heads of the two open source projects (Elmar Sonnenschein and Brunno Silva, respectively, maintain j2meunit and jmunit) and are planning to merge the two frameworks into one. The new project will be further consolidated on the basis of the J2meunit project. According to Sonnenschein, "because more of the existing user's work is based on the J2meunit framework on SourceForge, we plan to create a Jmunit 2.0 release based on Brunno J2meunit 2.0." "Silva said at a recent news conference that it might not be possible to complete product consolidation and a 2.0 release by the end of the year. Silva further suggested that the new project "does not want to break the existing code of the current user of these two frameworks, so the original code will continue to exist, just no longer recommended." The new unit framework should show the respective characteristics of the two frameworks-jmunit and j2meunit-. "

三、一个 a simple sample application

Before you analyze the various unit test frameworks, you need some simple code for testing purposes. In this example, the following simple conversion class 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;
 }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.