You can use the lifecycle test pattern to test the lifecycle methods
(creating new beans, removing beans, and finding beans) of session beans and
to test the state of a stateful session bean.
To test the lifecycle methods of a session bean:
- Click and click Next.
This opens the Create Test for EJB wizard.
- On the first wizard page, take one of the following actions:
- Select the test project that will contain the test and click Next.
- Click New to start the process of creating
a new test project.
At this point, a static analysis is performed on the EJBs associated
with the test project. These files were selected during the creation of the
test project and serve to define the scope of the test. (To update the list
of files in the project, modify the Test Scope properties of the test project.)
When
the analysis is complete, you will see a list of components in a table format
and sorted according to the computed metrics. You can use the guidance that
these metrics provide to decide which EJB components are most important for
you to test. Components with highlighted values or high numerical values are
considered high-priority test candidates.
- On the "Select the components under test" page, select the components
you want to include in the test and click Next.
- On the "Select a test pattern" page, select EJB lifecycle
testing and click Next.
- On the "Select the EJB interfaces" page, select the interfaces
(local or remote) you want to use to perform the test.
Note: You
cannot test an EJB through its local interface and through its remote interface
within the same component test or test suite. You must create one component
test to test through the local interface and a second component test to test
through the remote interface. You can store the two component tests in the
same test project.
- If you are testing a stateless session bean, click Finish to
create the test. If you are testing a stateful session bean:
- Click Next.
- On the "Select create method and fields" page, select the particular
create method to use to build the EJB under test, select the fields to be
tested, and click Finish.
Note: This page
is only available for stateful session beans because stateless session beans
are not expected to have fields.
The end result is a test behavior script and a test suite with
one test case.
- After you create the test, be sure to populate the test data table
with test data. To display a test data table, take one of the
following actions:
- Open the test behavior script and position the cursor within a test
method.
- Click a method in the Outline view.