 |
AppPerfect Unit Tester |
Tutorial : Unit Testing a Eclipse Plugin Project
This tutorial provides a brief introduction to the Unit Tester product of the
AppPerfect DevTest4J using a set practice exercises. This tutorial assumes you have
successfully downloaded and installed AppPerfect DevTest4J on your machine with the default
options. Apart from this pre-requisite, this tutorial is self contained. Instructions given below
are Windows-specific; if you are using a non-Windows machine, please use equivalent
commands/instructions.
This document is divided into following sections
- Creating Common Project
- AppPerfect Unit Tester
In this tutorial, we will discuss generating Test Cases for Eclipse plugin projects. Unit testing of
Eclipse plugins is supported only when product is integrated in Eclipse IDE. Eclipse plugin project
is like a local project but runs only in Eclipse platform.
Within each section, multiple exercises are listed. Each exercise forms a logical unit
which is expected to take no more than a few minutes to perform.
All exercises assume you have installed the product in C:\AppPerfect\DevTest folder and will
be referred as DEVTEST_HOME henceforth in tutorial. If you have installed the product in
some other folder, modify the instructions below appropriately.
This tutorial is not intended as a comprehensive training guide. Please refer to the
product documentation for detailed information. However, this tutorial will give you a very good overview
of the products and substantially improve your productivity with the product.
Creating Common Project
In AppPerfect DevTest4J, you can create a common project and use the same project to perform tests in all
the bundled products.
Exercise 1: Launch AppPerfect DevTest4J
Action:
- Eclipse Plugin unit testing is supported only when product is integrated with Eclipse IDE. Hence to
launch product, select a plugin project in package explorer in Eclipse and launch UnitTester. You can launch
Unit Tester either from context menu or from main menu AppPercet > Unit Tester
Exercise 2: Creating a Common Project
DevTest4J will create a new project named .apdevtest (if the action is invoked for the
first time, later on there is no need to create project as its already present). Settings of the newly created
project will be picked from the selected Eclipse project and will be displayed in the Common Project dialog.
Unit tester project properties dialog will be displayed on finishing the common dialog.
Action:
- On launching product, Unit Tester will bring up Common Project dialog with pre-filled values.
- Go through the instruction provided on top of the General tab.
- Unit Tester will pick the required settings from the Eclipse plugin, go through all tabs to verify the
settings picked and change them if needed. In the last target tab, click on the Finish button.
- A confirmation message saying that the project is saved will be displayed. Click on the OK button.
Now using this common project we will create tests to demonstrate the functionalities of AppPerfect
Unit Tester product.
AppPerfect Unit Tester
NB:Please follow the steps provided in the "Creating Common Project" section to first create a common project,
then proceed further.
Exercise 1: Define a Unit Tester project
Action:
- Once the common project is successfully created another dialog - Define Project Properties dialog -
will be displayed.
- Read the instructions at top of each tab.
- First tab of this dialog is Launch configuration settings. Select the Product or Application to run
and list of plugins to include.
- The Test Case Generation tab allows you to specify Test Class Generation settings, you can select the
various TestCase options. Keep default values.
- In Test Case Execution tab you can specify Test Class Execution settings. Keep default values.
- Click on the OK button to close this dialog.
Exercise 2: Testcase Generation
Action:
- Once a project is defined, the next step is to generate the necessary unit test cases. AppPerfect Unit
Tester automates the generation of such unit test cases. For .java files, the JUnit framework is used. For .jsp
files, the HttpUnit framework is used. Launch Test Generation Dialog by clicking on Project ->
Generate Test Cases... menu option.
- Click on Test Classes tab.
- In 'Generating test classes' section AppPerfect will generate test classes for source files provided
(which were added in the source tab of Common Project Wizard) and add instances created to Object Repository.
You can see the number Source files, Test classes generated, Testcases generated and Files ignored etc.
Click on Start Generation button.
- A check mark will be displayed against the files for which test classes are generated. Click OK once
generation is done.
- Select the Test Classes tab on the l.h.s. and expand the EJB node and Source Files node to view
the testclasses generated for the EJB and JAVA files.
- Select a Testclass to view its details on the r.h.s panel.
- Right click on a testclass and select "Open with Java Editor" to view/edit its source code.
- The source will be displayed in the editor on the r.h.s. For this exercise, we will not modify
the testclass.
Exercise 3: Execute the unit test and view/analyze results
Action:
- Start unit testing by clicking on Project -> Run.
- A new instance of target Eclipse will be launched for executing the test classes for unit testing
Eclipse plugin
- Select the Execution Summary node in the Results tab to get an overview of the test result.
- Select the Test Class node. On the r.h.s select Execution Results and expand the Source Classes
to view its test result.
- A list of all the exceptions / assertions will be displayed under the Exceptions view on the r.h.s.
Select individual exception / assertion and click "View stack trace" to view the error details.
Rectify the error and repeat the test as needed.