# 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 and select the New > JMUnit Test Case wizard.
2. On the New JMUnit Test Case wizard, select the appropriate information for the Test Case to be generated.

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.

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.

### Creating a Test Suite

1. In the Package Explorer view, right click the src folder and select the New > JMUnit Test Suite wizard.
2. On the New JMUnit Test Suite wizard, select the appropriate information for the Test Suite to be generated.

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.

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.

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

# 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.

- The Emulator shall initialize into the screen below:

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

# Debugging Tests

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