Creating tests for EJB business methods

You can use the EJB business logic test pattern to test the actual business logic of your Enterprise JavaBeans™ (EJBs). Because business logic is usually implemented in session beans, you usually test business logic by testing session beans. To test EJB business methods, you create a test scenario, similar to what you do when you create a scenario to test Java™ components.

When testing business methods, be sure to test the business logic itself, that is, the algorithms that process data in parameters. Also, be sure to use the test data table to do data-driven testing on a wide range of input data.

To test the business logic of an Enterprise JavaBean:

  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, take one of the following actions:
    • Select the test project that will contain the test and click Next.
    • Click New to create 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 for 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.

  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 business logic testing and click Next. This pattern creates a scenario for testing the business logic of the EJB under test.
  5. 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.
  6. On the "Define a test scenario" page, create the test scenario by selecting the create methods, business methods, and other methods that you want to include in the test.
    1. Add at least one instance of the EJB under test by selecting a create method from the list and clicking Add. (You can also double-click any method to add it to the scenario.)
    2. To assign a meaningful name to the EJB instance, select the instance from the test scenario, click Rename, enter the new name, and click OK.
    3. Double-click each additional method to be included in the scenario.
    4. When you are finished building the scenario, click Finish.
    The end result is a test behavior script and a test suite with one test case for the entire scenario.

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:

Related concepts
Test patterns for Enterprise JavaBeans
Static metrics
Related tasks
Creating new component test projects
Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.