Creating scenario-based Java tests

Scenario-based testing consists of testing a particular sequence of method calls from one or several public classes. When you create a scenario-based test, a single test case is created based on the sequence of method calls selected in the wizard.

To create a scenario-based Java test:

  1. Click File > New > Other > Component Test > Java > Java Component Test and click Next.

    This starts the New Java Component Test wizard.

  2. On the first wizard page, select the test project that will contain the test or click New to create a new project, and then click Next.

    At this point, a static analysis is performed on the Java source files 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 classes or 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 the Scenario-based testing pattern and click Next.

  5. On the Define a test scenario page, create the test scenario by selecting the constructors and methods that you want to include in the test.

    1. Add one or several instances of the class-under-test by selecting a constructor from the list and clicking Add. (You can also double-click a constructor to add it to the scenario.)

    2. To assign a meaningful name to the class instance, select the instance from the test scenario, click Rename, enter the new name, and click OK.

    3. Double-click each 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.

 

Related concepts

Static metrics
Standard Java test patterns

 

Related tasks

Creating new component test projects

Related reference
Static metrics reference