< Previous | Next >

Lesson 3: Optional: Test your code with the test classes

At this point in the tutorial, you can use the test class to test the code that you just wrote. This lesson is optional, but shows you how to run the test class.

To run the test class:

  1. Open the InventoryLevelsDataTest.java file for editing by double-clicking the file in the Package Explorer.
  2. Add this simple method and save the file:
    			short inventoryYear = 2007;
    			short inventoryMonth = 1;
    			int warehouseBranchCode = 7;
    			int productNumber = 10110;
          Integer getQuantityShipped = data.getQuantityShipped(inventoryYear,inventoryMonth,warehouseBranchCode,productNumber);
    			SampleUtil.println("Result for getQuantityShipped():" + getQuantityShipped.toString());	
  3. In the Package Explorer, right-click the file and select Run As > Run Configuration.
  4. In the Run Configurations window, double-click Java Application. A new run configuration named InventoryLevelsDataTest opens. This run configuration will run the InventoryLevelsDataTest class.
  5. On the Arguments page of the Run Configurations window, type the connection URL, user ID, and password for the connection to the GSDB database, as in this example.
    Figure 1. Typing the connection URL, user ID, and password on the Arguments page of the Run Configurations window
    Typing the connection URL, user ID, and password on the Arguments page of the Run Configurations window
  6. Click Apply, then click Run. The results appear in the Console view for all of the SQL statements that InventoryLevelsDataTest runs. The following figure highlights the result for the getQuantityShipped() method.
    Figure 2. The results of running InventoryLevelsDataTest, with the result of the getQuantityShipped() method highlighted
    Results for testing the InventoryLevelsData interface
< Previous | Next >

Feedback