CN101510171A - Midlet main main class test method for java ME software - Google Patents

Midlet main main class test method for java ME software Download PDF

Info

Publication number
CN101510171A
CN101510171A CNA2009100108994A CN200910010899A CN101510171A CN 101510171 A CN101510171 A CN 101510171A CN A2009100108994 A CNA2009100108994 A CN A2009100108994A CN 200910010899 A CN200910010899 A CN 200910010899A CN 101510171 A CN101510171 A CN 101510171A
Authority
CN
China
Prior art keywords
midlet
class
test
main classes
testcase
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CNA2009100108994A
Other languages
Chinese (zh)
Inventor
杜振军
陈荣
王正磊
王文军
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Dalian Maritime University
Original Assignee
Dalian Maritime University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Dalian Maritime University filed Critical Dalian Maritime University
Priority to CNA2009100108994A priority Critical patent/CN101510171A/en
Publication of CN101510171A publication Critical patent/CN101510171A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention discloses a test method for testing the MIDlet main class of JavaME software. The method establishes a manner of combining a common test class and a special test class of the MIDlet main class to realize the test to the MIDlet main class; by carrying out source code instrumentation to the MIDlet main class, the special test class can preserve the MIDlet class identification simultaneously when becoming the a TestCase class; the test method and a source method are put into the same class so as to bring convenience for carrying out writing test to private methods and also realize the writing test of methods relevant to the user interface in the MIDlet main class; and the customization of a TestSuite class can ensure the unified management of various test classes of the MIDlet main class and other test classes. The invention realizes the complete test to the MIDlet main class under the test framework of JMUnit for the first time. The invention is suitable for being widely applied to the test of the application programs of JavaME mobile devices.

Description

Method of testing at MIDlet main classes in the Java ME software
Technical field
The present invention relates to a kind of embedded software test method, relate in particular to the method for testing of the MIDlet main classes in a kind of Java ME embedded software.
Background technology
Java ME (Java Micro Edition) also is known as J2ME, is the Java language platform of the height optimization that provides of the embedded consumer-elcetronics devices for set-top box, mobile phone and PDA and so on.MIDlet is a kind of Java ME application program that operates on the equipment that meets the MIDP standard, is current main a kind of JavaME Application Type.Support the mobile phone of Java all to support MIDlet at present.A MIDlet comprises that at least one derives from the java class from the abstract class javax.microedition.midlet.MIDlet of MIDP definition, and we claim that this java class is the MIDlet main classes.
XUnit writes the most frequently used framework of software test case.In fact, it is the one group of test frame that is applicable to different programming languages and different application purpose, wherein JUnit is most widely used Java test frame based on xUnit, but this framework can not directly be used in Java ME environment, because not supporting reflex of Java ME API, and reflection API just JUnit must use.People do a lot of work JUnit are transplanted to Java ME field, wherein mainly contain three kinds of J2MEUnit and JMUnit and Mobile JUnit, and JMUnit more becomes mobile process developer's first-selection with the efficient, easy-to-use, simple of it and good characteristic such as increase income.
Yet all there is a problem that is difficult to solution in the test case of writing based on these popular Java ME test frames at present, is exactly all can't carry out complete test to the MIDlet main classes.Because the MIDlet main classes is realized test, maximum obstacle is the problem of MIDlet instantiation, because current MIDP standard does not allow instantiation MIDlet in application program (have only AMS---the virtual machine aspect just has such mandate).Therefore the test case of current Java ME program all is to set up at non-MIDlet class, all in the problem of avoiding the test of MIDlet main classes.Thereby also directly influenced the integrality of MIDlet Application testing.In current most popular Java ME test frame JMUnit, realize that a kind of method that the MIDlet main classes is carried out complete test has positive meaning, also be urgent problem.
Summary of the invention
The present invention is directed to the proposition of above problem, and develop a kind of method of testing at the MIDlet main classes in the Java ME embedded software.The mode that it combines with special test class by the conventionally test class of setting up the MIDlet main classes realizes the test to the MIDlet main classes; Special test class is by the MIDlet main classes is done the source code plug-in mounting, become a TestCase class when realizing keeping MIDlet class identity again, method of testing and former method are placed in the same class, do not need in method of testing, tested class to be done instantiation, and can write test to private method easily, also can realize the relevant method of user interface in the MIDlet main classes is write test; By customization TestSuite class, can be with the test class unified management of various test class and other classes of MIDlet main classes.Its specific implementation technological means is as follows:
The method of testing of the MIDlet main classes in a kind of Java ME embedded software is characterized in that, may further comprise the steps:
A, at first by the mode of setting up conventional TestCase class in the JMUnit test frame, generates one or more conventional TestCase classes at the MIDlet main classes;
B, then under the situation that the MIDlet main classes is backuped, does the source code plug-in mounting with the MIDlet main classes, makes it to become the special TestCase class under the JMUnit framework;
C, set up the TestSuite class, the two kinds of TestCase classes that above-mentioned two steps are built up and the TestCase class of other classes add unified management among the TestSuite;
D, move the TestSuite class that obtains previously in the mode that starts MIDlet and test.
The implementation following steps of step a:
(1) in the building method of TestCase class, obtain an instance objects of MIDlet main classes;
(2) each method of testing in the TestCase class all will be quoted the instance objects that obtains in (1) main classes is tested.
The concrete steps of described step b are as follows:
(1) the MIDlet main classes is backuped;
(2) parent of the former MIDlet main classes of modification is the TestCase class;
(3) on the basis of the building method body content that keeps the MIDlet main classes, in the building method body, add calling to parent TestCase class formation method;
(4) life cycle in the MIDlet main classes is relevant method is renamed;
(5) in the MIDlet main classes, add each method of testing.
In the described step (5), the method for testing of adding in the MIDlet main classes is as follows:
(1) adds each method of testing of doing test at the former method in the MIDlet main classes;
(2) under the condition of the requirement of observing the JMUnit framework, realize the management method of test execution, and realize setUp and tearDown method in the usual way;
The class of TestCase described in the step c adds among the TestSuite, employing is a parent with the TestSuite class in the JMUnit framework, customize the TestSuite class that needs in this method of testing, in the building method body of this TestSuite class, use the add method to add the example of the TestCase class of front reincarnate.
The class of TestCase described in the step c adds among the TestSuite, can also adopt TestSuite class default among the JMUnit, directly increases each TestCase class of JMUnitTestClasses attribute description in the JAD file.
The present invention has realized a kind of method that can do complete test to the MIDlet main classes, can in the Java of current popular ME test frame JMUnit, realize, the JMUnit test frame itself is not done change, do not influence other non-MIDlet classes are done test, and can be with the test of MIDlet main classes and the test unified management of non-MIDlet class, can be seamless integrated with test frame.This method can be used as the supplementary functions of current test frame, is easy to implement, can the integrated easily Eclipse of advancing and popular development platform such as Netbeans in use.
Description of drawings
Fig. 1 is an implementation process process flow diagram of the present invention.
Fig. 2 is at a result of implementation figure on the NetBeans platform.
Embodiment
In conjunction with process flow diagram shown in Figure 1, specific implementation process of the present invention is described.
At first, by the mode of setting up conventional TestCase class in the JMUnit test frame, generate a conventional TestCase class at the MIDlet main classes.
(1) in the building method of TestCase class, obtain an instance objects of MIDlet main classes.Because the TestCase class in the JMUnit test frame is a MIDlet, can obtain the example of another MIDlet in the building method of a MIDlet, also only in this way just can obtain a MIDlet example can handling in program;
(2) each method of testing in the TestCase class all will be quoted the instance objects that obtains in (1) main classes is tested.
This TestCase class at the MIDlet main classes can be done test to the non-private method of part in the MIDlet main classes, may have some simple MIDlet main classes and only need go test to get final product with the TestCase class of this routine.But to the test of general MIDlet main classes, need set up following special TestCase class, to realize that the conventional difficult method of surveying is write test toward contact.
Then, after the MIDlet main classes is backuped, the MIDlet main classes is done the source code plug-in mounting, make it to become the special TestCase class under the JMUnit framework.Realize that the identity that had both kept the MIDlet class becomes a TestCase class again.
(1) the MIDlet main classes is backuped.
(2) adopting mode to the direct injecting codes of MIDlet main classes, and do not change MIDlet main classes name, is because may use MIDlet main classes class name in other classes.In the MIDlet main classes, add importing to the jmunit class libraries; Parent with the MIDlet main classes is revised as TestCase by MIDlet then.Because the TestCase class itself is a MIDlet class, so also can keep the MIDlet identity characteristic of former MIDlet main classes.
(3) on the basis of the building method body content that keeps the MIDlet main classes, in the building method body, add the calling of parent TestCase class formation method, realize that method of testing number and test class descriptor are to the transmission of test frame in this class.Only needing first trip in the building method body of MIDlet main classes to call super method (descriptor of method of testing number and test class is as its parameter in this class) gets final product.
(4) realize both having kept the method that the life cycle in the former MIDlet main classes is correlated with, the life cycle management of deferring to the TestCase class again.The mode of taking the method that the life cycle in the MIDlet main classes is relevant to rename, the life cycle methodology that need rename comprises startApp, pauseApp and destroyApp.
(5) add each method of testing, realize the management method of test execution, and realize setUp method and tearDown method as required.Directly in the MIDlet main classes, add following method:
(a) add each method of testing of doing test at the former method in the MIDlet main classes, because former method and method of testing do not need in method of testing tested class to be done instantiation in same class.Can realize these difficult methods of surveying such as method that private method, user interface in the MIDlet main classes are correlated with are write test.
(b) realize the management method (test method, it is the abstract method of parent) of test execution, realize this method as long as observe the requirement of JMUnit framework.In addition, as required, can realize setUp and tearDown method in the usual way.
So just obtained by the next special TestCase class of MIDlet main classes transformation.
Then, set up a TestSuite class, two kinds of TestCase classes building up are previously added among the TestSuite.As having a plurality of MIDlet main classes to survey in the Java ME project, all can obtain corresponding TestCase class and join among the TestSuite by preceding step.In addition, if the user also has the TestCase class of other non-MIDlet main classes, also can all join unified management among the TestSuite.Can adopt one of following dual mode.
(1) is parent with the TestSuite class in the JMUnit framework, customizes the TestSuite class that needs in this method of testing, in the building method body of this TestSuite class, use the add method to add the example of the TestCase class of front reincarnate.Attention can only be finished the interpolation of above TestCase in the building method body of TestSuite class.
In addition, need in the MIDlet list items of MIDlet external member property file (inventory file and JAD file), add the good TestSuite class name of customization.
(2) can also adopt TestSuite class default in the JMUnit framework.Need add jmunit.framework.cldclx.TestSuite in the MIDlet list items of MIDlet external member attribute, and increase an attribute JMUnitTestClasses in the JAD file, its value is a plurality of complete TestCase class name with space-separated.
At last, the TestSuite class that operation obtains previously in the JMUnit framework.Adopt the mode of moving the TestSuite class rather than the mode of directly moving the TestCase class, be because be convenient to management of test cases, the test case of MIDlet main classes and the test case unified management of other classes can be moved, and TestSuite operation test is more suitable for testing the multi-threading method relevant with user interface with the mode of display result.
The present invention can implement in various common development platforms, and Fig. 1 is the implementing procedure figure of this method.(contain two MIDlet main classes: calculator.CalculatorMIDlet and calculator.AnotherMIDlet at a concrete MIDlet project below, and contain a non-MIDlet class: math.Arithmetic), with Netbeans5.x/6.x development platform (the Mobility Pack plug-in unit of supporting Java ME has been installed) is example, and suppose the user selects the JMUnit storehouse of CLDCl1 for use, elaborates how under the JMUnit framework above three classes all to be done test with the inventive method.For convenience, mainly be that example is done concrete implementation with CalculatorMIDlet.
1, in MIDlet item attribute/storehouse and resource items, added the JMUnit storehouse of CLDCll after, by the mode of setting up conventional TestCase class in the JMUnit test frame, generate a conventional TestCase class, as CalculatorMIDletSimpleTest at the CalculatorMIDlet class.Be used for 4 straightforward procedures of CalculatorMIDlet class are done test.Add the class variable statement of CalculatorMIDlet type, as private CalculatorMIDlet instance; In the building method of CalculatorMIDletSimpleTest, add instantiation CalculatorMIDlet category code.As:
public?CalculatorMIDletSimpleTest(){
Super (4, " CalculatorMIDlet Conventional Test "); 4 method of testings are arranged in // this class
Instance=new calculator.CalculatorMIDlet (); // obtain the example of tested MIDlet herein
}
Annotate: an example that only just can obtain CalculatorMIDlet in above position; Each method of testing in the CalculatorMIDletTest class all will be quoted the above instance that obtains, and could test the method among the CalculatorMIDlet.
Above conventional TestCase class CalculatorMIDletSimpleTest only is fit to survey 4 simple publicly-owned methods among the CalculatorMIDlet, is difficult to test for remaining 6 method.Therefore also need set up special TestCase class
2, MIDlet main classes plug-in mounting is become special TestCase class under the JMUnit framework.
(1) tested MIDlet main classes file is backuped, as the CalculatorMIDlet.java file is backuped, backup file is called CalculatorMIDlet.java-orig;
In the CalculatorMIDlet class, add importing code to the jmunit class libraries:
import?jmunit.framework.cldcll.*;
(2) revise such parent: change extends TestCase into by extends MIDlet.
(3) owing to will build 6 method of testings in this class,, the first trip in the building method body of CalculatorMIDlet class gets final product so increasing following code newly:
super(6,“CalculatorMIDlet?Special?Test”);
(4) CalculatorMIDlet class Central Plains startApp, pauseApp, destroyApp method are renamed as orig $ startApp, orig $ pauseApp, orig $ destroyApp.
(5) in the CalculatorMIDlet class, inject following method:
(a) owing to will respectively write a method of testing, in the CalculatorMIDlet class, directly add testcommandAction (), testorig $ startApp 6 method of testings such as () to the commandAction () in this example, orig $ startApp 6 methods such as ().The contents are as follows such as former orig $ startApp () method part:
public?void?orig$startApp(){
… … …
count=101;
getDisplay().setCurrent(get_calculatorForm());
}
A method of testing setting up it is:
public?void?testorig$startApp()throws?AssertionFailedException{
System.out.println(″startApp″);
int?expectedCount=101;
String?expectedTitle=″Calculator″;
orig$startApp();
assertEquals(expectedCount,count);
assertEquals(expectedTitle,getDisplay().getCurrent().getTitle());
}
The part of former commandAction () method thes contents are as follows:
public?void?commandAction(Command?command,Displayable?displayable){
… … …
a=Integer.parseInt(get_field_a().getString());
b=Integer.parseInt(get_field_b().getString());
… … …
else?if(command==addCommand){
get_resultItem().setText(Integer.toString(Arithmetic.getInstance().add(a,b)));
getDisplay().setCurrent(get_calculatorForm());
}
… … …
}
A method of testing setting up it is
public?void?testcommandAction()throws?AssertionFailedException{
System.out.println(″commandAction″);
String?expectedResult=″256″;
get_field_a().setString(″67″);
get_field_a().setString(″189″);
commandAction(addCommand,calculatorForm);
assertEquals(expectedResult,get_resultItem().getText());
}
This does not give unnecessary details other method of testings.
(b) realize the abstract method test () that management testing is carried out in the parent, following form:
public?void?test(int?testNumber)throws?Throwable{
switch(testNumber){
case?0:testcommandAction();break;
case?1:testorig$startApp();break;
case?2:testget_calculatorForm();break;
… …
case?5:test?get_resultItem();break;
default:break;
}
}
(c) realize setUp () and tearDown () method as required.These two methods are empty temporarily in this example.
CalculatorMIDlet class after the change that obtains like this is a TestCase class in the complete JMUnit framework.
For another MIDlet class calculator.AnotherMIDlet in this example, because the method body of the inside all is very simple publicly-owned method, the test class that only need set up a routine gets final product, as calculator.AnotherMIDletTest (wherein setting up 4 method of testings).Other classes math.Arithmetic in this example generates the TestCase class in a conventional manner and gets final product, such as the test class that generates math.ArithmeticTest (wherein setting up 5 method of testings) by name.
3. set up TestSuite class testsuite.MyTestSuite by name, its body matter is as follows:
import?jmunit.framework.cldcll.TestSuite;
public?class?MyTestSuite?extends?TestSuite{
public?MyTestSuite(){
super(″My?Test?Suite″);
add(new?calculator.CalculatorMIDlet());
add(new?calculator.CalculatorMIDletSimpleTest());
add(new?calculator.AnotherMIDletTest());
add(new?math.ArithmeticTest());
}
}
The TestCase class that the TestCase class of two MIDlet generations and non-MIDlet generate all is added among the MyTestSuite.
In the MIDlet list items of MIDlet external member attribute, add following:
Title: MyTestSuite class: testsuite.MyTestSuite icon: can be sky.
Perhaps, the user can select not customize above MyTestSuite class, but directly adopts jmunit.framework.cldcll.TestSuite class default in the JMUnit framework.Only need in the MIDlet list items of MIDlet external member attribute, add following:
Title: MyTestSuite class: jmunit.framework.cldcll.TestSuite;
And in the JAD attribute, increase as the next item down:
Title: JMUnitTestClasses value: four TestCase classes in this example of separating with the space.
4. in NetBeans, move this MIDlet project, just can in mobile phone simulator startupoptions the MyTestSuite item appear, shown in Fig. 2 (a), after selecting MyTestSuite to start, the preceding interface of method of testing operation appears, shown in Fig. 2 (b), after the click " test ", 19 method of testings in three test class (two MIDlet test class and a non-MIDlet test class) are all moved operation result such as Fig. 2 (c).The implementation process of method can be made the feature card of NetBeans easily, is convenient to the user and directly uses.Implementation process on other development platforms is similar with the elaboration of above process in addition.
The above; only be the preferable embodiment of the present invention; but protection scope of the present invention is not limited thereto; anyly be familiar with those skilled in the art in the technical scope that the present invention discloses; be equal to replacement or change according to technical scheme of the present invention and inventive concept thereof, all should be encompassed within protection scope of the present invention.

Claims (3)

1, the method for testing of the MIDlet main classes in a kind of Java ME embedded software is characterized in that, may further comprise the steps:
A, at first by the mode of setting up conventional TestCase class in the JMUnit test frame, generates one or more conventional TestCase classes at the MIDlet main classes;
B, then under the situation that the MIDlet main classes is backuped, does the source code plug-in mounting with the MIDlet main classes, makes it to become the special TestCase class under the JMUnit framework;
C, set up the TestSuite class, the two kinds of TestCase classes that above-mentioned two steps are built up and the TestCase class of other classes add unified management among the TestSuite;
D, move the TestSuite class that obtains previously in the mode that starts MIDlet and test.
2, the method for testing of the MIDlet main classes in a kind of Java ME embedded software according to claim 1 is characterized in that the implementation of step a has the following steps:
(1) in the building method of TestCase class, obtain the instance objects of MIDlet main classes;
(2) each method of testing in the TestCase class all will be quoted the instance objects that obtains in (1) main classes is tested.
3, the method for testing of the MIDlet main classes in a kind of Java ME embedded software according to claim 1 is characterized in that the concrete steps of described step b are as follows:
(1) the MIDlet main classes is backuped;
(2) parent of the former MIDlet main classes of modification is the TestCase class;
(3) on the basis of the building method body content that keeps the MIDlet main classes, in the building method body, add calling to parent TestCase class formation method;
(4) life cycle in the MIDlet main classes is relevant method is renamed;
(5) in the MIDlet main classes, add each method of testing.
CNA2009100108994A 2009-03-25 2009-03-25 Midlet main main class test method for java ME software Pending CN101510171A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNA2009100108994A CN101510171A (en) 2009-03-25 2009-03-25 Midlet main main class test method for java ME software

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNA2009100108994A CN101510171A (en) 2009-03-25 2009-03-25 Midlet main main class test method for java ME software

Publications (1)

Publication Number Publication Date
CN101510171A true CN101510171A (en) 2009-08-19

Family

ID=41002574

Family Applications (1)

Application Number Title Priority Date Filing Date
CNA2009100108994A Pending CN101510171A (en) 2009-03-25 2009-03-25 Midlet main main class test method for java ME software

Country Status (1)

Country Link
CN (1) CN101510171A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103136102A (en) * 2013-02-07 2013-06-05 百度在线网络技术(北京)有限公司 Method and device for testing fluency of Android platform
CN103902458A (en) * 2014-04-18 2014-07-02 浪潮电子信息产业股份有限公司 Universal storage software test design method
CN103970664A (en) * 2014-05-27 2014-08-06 浪潮电子信息产业股份有限公司 Method for analyzing automatic test cost of module
CN105117336A (en) * 2015-08-26 2015-12-02 中国科学院软件研究所 Method for processing control dependence employing dynamic marking

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103136102A (en) * 2013-02-07 2013-06-05 百度在线网络技术(北京)有限公司 Method and device for testing fluency of Android platform
CN103136102B (en) * 2013-02-07 2018-06-12 百度在线网络技术(北京)有限公司 The fluency test method and device of a kind of Android platform
CN103902458A (en) * 2014-04-18 2014-07-02 浪潮电子信息产业股份有限公司 Universal storage software test design method
CN103902458B (en) * 2014-04-18 2017-12-05 浪潮电子信息产业股份有限公司 A kind of general storage software testing system and design method
CN103970664A (en) * 2014-05-27 2014-08-06 浪潮电子信息产业股份有限公司 Method for analyzing automatic test cost of module
CN105117336A (en) * 2015-08-26 2015-12-02 中国科学院软件研究所 Method for processing control dependence employing dynamic marking
CN105117336B (en) * 2015-08-26 2018-11-16 中国科学院软件研究所 A kind of method that dynamically labeled processing control relies on

Similar Documents

Publication Publication Date Title
Meier Professional Android 4 application development
US9400784B2 (en) Integrated application localization
US8954870B2 (en) System and method for extending a visualization platform
US8910113B2 (en) Methods and systems for visual code refactoring
CN111596909B (en) Method and medium for visually editing tree structure game logic
US8843892B2 (en) Visual representations of code in application development environments
US20050251788A1 (en) Methods and systems for generating a configurable user interface
Meier et al. Professional Android
US20170123762A1 (en) Graphical representation of data in a program code editor
CN102455912A (en) Runtime extensions
Schwarz et al. The Android developer's cookbook: building applications with the Android SDK
CN109800135A (en) A kind of information processing method and terminal
MacLean et al. Pro Android 5
Panigrahy Xamarin Mobile Application Development for Android
CN101510171A (en) Midlet main main class test method for java ME software
Dixit Android
CN107168738A (en) A kind of management method of application tool, device, equipment and storage medium
KR101416096B1 (en) A highly compatible plug-in system for developing hybrid web applications
CN109240696A (en) A kind of Oftware updating method and device
Delessio et al. Sams teach yourself Android application development in 24 hours
Lewis et al. Native mobile development: a cross-reference for iOS and Android
Lachgar et al. Dsl and code generator for accelerating ios apps development
KR101456507B1 (en) An authoring apparatus for applying n-screen to web application ui and the method for the same
Daniel Android Wearable Programming
Vavru et al. Android programming: Complete application programming guide

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C02 Deemed withdrawal of patent application after publication (patent law 2001)
WD01 Invention patent application deemed withdrawn after publication

Open date: 20090819