Creating tests for the lifecycle methods of entity beans

You can use the lifecycle test pattern to test the lifecycle methods (creating new beans, removing beans, and finding beans) of entity beans, to test the correctness of an entity bean's state, and to test persistence and database lookups of entity beans.

To test the lifecycle methods of an entity bean:
  1. Click File > New > Other > Component Test > EJB > EJB Component Test and click Next.

    This starts the Create Test for EJB wizard.

  2. On the first wizard page, do one of the following:
    • Select the test project that will contain the test and click Next.
    • Or 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. (The list of files in the project can be updated by modifying the test project's Test Scope properties.)

    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 help you 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.

  3. On the Select the components under test page, select the components you want to include in the test and click Next.
  4. On the Select a test pattern page, select EJB lifecycle testing and click Next.
  5. On the Select the EJB interfaces page, select the interfaces (local or remote) that you want to use to perform the test.
  6. 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. The end result is a test behavior script and a test suite with one test case.
  7. After you create the test, be sure to populate the test data table with test data. To display a test data table, you can do one of the following:
    • Open the test behavior script and position the cursor within a test method.
    • Click a method in the Outline view.

Related concepts
Test patterns for Enterprise JavaBeans
Static metrics

Related tasks
Creating new component test projects

Terms of use | Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.