Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Eclipse Java ME (J2ME) Developer Guide
Previous Page Home Next Page

Writing and running JMUnit tests

In this section, you will be using the JMUnit testing framework to write and run tests. To get started with JMUnit you can refer to the JMUnit user guide.

Writing Tests

JMUnit testing framework has two main concepts, test case and test suite. A test case is a class where tests targeting another class are written. Test suite is a class that aggregates lots of test cases, so if you wish to execute several test cases at once you must create a test suite to wrap them together.

Creating a Test Case

  1. In the Package Explorer view, right click the class you want to test href="eclipse_java_me_javascript:executeCommand("org.eclipse.ui.newWizard(newWizardId=org.eclipse.mtj.j2meunit.wizards.NewJ2METestCaseWizard)")"> Open the New JMUnit Test Case wizard New > JMUnit Test Case wizard.

    Select the JMUnit Test Case wizard

  2. On the New JMUnit Test Case wizard, select the appropriate information for the Test Case to be generated.

    TestCase creation Wizard page 1

  3. You will see a warning message asking you to add the JMUnit library to the build path. Use the Click here link to add the JMUnit library automatically.
  4. After having added JMUnit on the class path in case it was not already configured, the Next and Finish buttons will be enabled.

    Note: You now can either click Finish to create the Test Case, or click Next to set up the methods to be tested on the Test Methods page.

  5. The Test Methods page is used to choose all methods to be tested in the new Test Case that will be created.

    TestCase creation Wizard page 2

  6. Select all methods that should be tested in your Test Case.
  7. To finish the JMUnit Test Case creation wizard, simply click on the Finish button and the new test case will be created in your workspace.

If you have completed the above steps, the Package Explorer view will now contain the JMUnit Test Case we just created, and the it will be opened by the java editor.

TestCase Class

Creating a Test Suite

  1. In the Package Explorer view, right click the src folder href="eclipse_java_me_javascript:executeCommand("org.eclipse.ui.newWizard(newWizardId=org.eclipse.mtj.j2meunit.internal.ui.wizards.NewJ2METestSuiteCreationWizard)")"> Open the JMUnit Test Suite wizard New > JMUnit Test Suite wizard.

    Select the JMUnit Test Suite wizard

  2. On the New JMUnit Test Suite wizard, select the appropriate information for the Test Suite to be generated.

    TestSuite creation Wizard page 1

  3. Select the classes that should be included in the suite. We currently have a single test class only, but you can add to the suite later.
  4. You can add or remove test classes from the test suite in two ways:

    • Manually by editing the test suite file
    • By selecting a test suite in the source tree and selecting "Update JMUnit Test Suite..."

    Note: the wizard adds 2 markers, //JMUnit-BEGIN and //JMUnit-END, into the created Test suite class, which allows the wizard to update existing test suite classes. Editing code between the markers is not recommended.

  5. Press "Finish".
  6. A new TestSuite Class is created and opened on the java editor.

  7. TestSuite Class

Running Tests

  • Running either a test case or a test suite is done by running the class as an "Emulated Java ME MIDlet" as show bellow.

  • Running Test

  • The Emulator shall initialize into the screen below:

  • Emulator Run

  • Select "Test" to run the tests.
  • The test results are shown bellow.

  • Emulator Results

Debugging Tests

  • Debugging tests is done as debugging a regular Java class since both TestCase and TestSuite extend MIDlet class.

  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire