Using a Modular Approach: Composing Tests


One of the handy features of the Test Composer is that you can compose tests before you write the scripts that make up the test. Defining the JST files first can help you determine which scripts you need to write, whether they will be re-usable, and, later on, when you can re-use a test by adding parameters.

For this part of the lesson, you're going to use the Test Composer to compose three JavaStar Tests:

The first two tests represent the major areas covered by the script you wrote in the previous chapter. The last JST, the Acceptance test, combines the two previous tests with an OpenFile script. This creates a test that functions just like the long script, but is composed of modules you can re-use in other configurations.

You create the Acceptance test last because, while you can define a JST before you've written the scripts that it references, you can't reference another JST that hasn't yet been written.

Entering a Record

This first JST handles record entry. As you noted when you reviewed the example earlier, this record entry portion of the script did three things:

Now you'll create a JST with a node for each of these operations.

  1. Open the Test Composer.
    Click Compose Test in the JavaStar main menu. See Figure 5-2 for a screen shot of this window.

    JavaStar Test Composer

The blank panel in the middle/right area of the Test Composer window is the work area where you graphically define your test. The buttons along the left control the file and the nodes you create, while the fields above the work area are where you define general information about your test, and where you navigate to other JSTs.

  1. Add your first test node.
    You can do this in two ways:

  2. In response to the Test Name dialog, enter ClearDisplay as the name of your node.
    Because you are defining tests you haven't yet written, enter the name of the script you plan to write. When you run the test, JavaStar looks for a .class file by this name, so be precise. In this case, type ClearDisplay and click OK.

    Note - If you wanted to reference another JST file instead of a .class file, you would need to use the .jst extension.

  3. Create two more test nodes: one named EnterFieldData and the other named Add.

  4. Position the nodes so that ClearDisplay is toward the top of the work area, with EnterFieldData below ClearDisplay and Add below EnterFieldData.
    You can click and drag a node to re-position it.

  5. Draw a normal connection from ClearDisplay to EnterFieldData.
    To create a normal connection:

    1. Click on the ClearDisplay node to select it.

    2. From the buttons to the left, choose Start Normal.
      ClearDisplay flashes to let you know an operation is in progress.

    3. Click on EnterFieldData to select it as the end point.
      JavaStar draws a green line from ClearDisplay to EnterFieldData.

  6. Draw a normal connecting line from EnterFieldData to Add.

  7. Duplicate the ClearDisplay node.
    Click on ClearDisplay to select it, then click the Duplicate button in the left button panel.

  8. Click and drag the ClearDisplay node to a position below the Add node.

  9. Draw a normal connection from Add to the second ClearDisplay node.

  10. For Comments, type Adds 1 record to the database.
    Your work area should look like this:

    AddRecord.jst

The first node you created, ClearDisplay, appears in blue to indicate that it is the root or starting node. This is the node that the test will execute first. You can change a root starting node by selecting another node and clicking the Set Root button.

  1. In the JST name field (located toward the top of the window), enter AddRecord.jst.

  2. Click the Save button.

  3. Click Reset to clear the display and begin a new JST.

Verifying Search Results

This JST verifies that the name matches the record you added. In the TestNameDB script you created in the previous chapter, you:

Because it's rare that you would perform a search and not select a record to view, this JST assumes you're combining these into one script, but leaving the rest of the steps as separate scripts.

  1. Create five nodes: OpenSearch, DefineSearch, GetSearchResults, VerifyRecord, and CloseSearch.

  2. Position the nodes so that one is above the other, in the order listed.

  3. Using the Start Normal button, draw connecting arrows from each node to the one below it.

  4. In the Comments field, type Searches for a record and verifies that the result is correct.
    Your work area should look like this:

    VerifySearch.jst

  5. Enter VerifySearch.jst in the JST name field.

  6. Click Save.

  7. Click Reset.

The Acceptance Test

The script you wrote in the last chapter will be the model for this acceptance that draws all the test modules (the ones you have yet to write) together. This means the acceptance test needs to:

The steps for adding records and verifying the name are now already defined by other JSTs and only need to be referenced. For loading a file, you need to create a node for another script you'll write. ClearDisplay is a script you've already referenced (but not yet written) in AddRecords.jst, so you'll use the same name again.

To define the acceptance test:

  1. Click Add Test.

  2. Enter OpenFile as the test name and click OK.

  3. Add another test and specify AddRecord.jst as the test name.
    Click Add test. For Test name, click the browse button, locate AddRecord.jst, and click Open. Then click OK.
    JavaStar creates a rectangle with rounded corners to show that this node launches another JST, rather than running a .class file.

  4. Add a node named SaveDB.
    This node has squared corners, indicating it points to a script.

  5. Create another node, this one pointing to VerifySearch.jst.
    You can type the names in instead of browsing, but if you forget the .jst extension or misspell the name, JavaStar won't find the file you want.

  6. Add a node named ClearDisplay.

  7. Add a node named CloseDB.

  8. Organize the nodes in the order you plan to run them.
    See the list at the opening of this section.

  9. Create normal connections from each node to the next.

  10. For Comments, type Simple acceptance test for Name Database.
    Your work area should look like:

    Acceptance.jst

  11. In the JST name field, enter Acceptance.jst.

  12. Click Save.

  13. Close the Test Composer.



Send feedback to JavaStar-feedback@suntest.com
Copyright © 1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, CA 94303. All rights reserved.