Product Information > JADE Developer’s Reference > Chapter 17 - Using the JADE Testing Framework > Generating a Web Service Consumer Unit Test Class and Stub Methods

Generating a Web Service Consumer Unit Test Class and Stub Methods

You can generate a set of stub methods that can be used for Web service consumer unit testing.

In the description in this section, the sample Web service that is used is called CustomerService, which exposes the three methods shown in the following diagram.

To generate stub methods for your Web service consumer

  1. Select the Generate Test Case command from the Classes menu in the Class Browser.

    This command is enabled only when the selected class is a subclass of the JadeWebServiceConsumer class.

    The Generate Test Case dialog, shown in the following diagram, is then displayed.

  2. In the Test Name text box, change the unit test class, if required. The name of the JadeTestCase subclass that is created defaults to the Web service consumer name (CustomerService, in this example) subclass name (CustomerService, in the example in this section) with the Test_ prefix.

    The Generate Test Case dialog lists all methods in the JadeWebServiceConsumer class subclass.

  3. In the table of methods defined in the Web service consumer subclass, check the check box in the Select column of each method for which you want a test case generated.

    Conversely, if you want to select all of the methods, check the Select All Methods check box. (Unchecking this check box does not affect the list of selected methods.)

  4. Check the Generate Parameter Defaults check box if you want to generate stub code for the method parameters.

  5. Check the Assert all tests as Incomplete check box if you want to add an assert to the method code to say that the test is not complete.

  6. Check the Generate Expected Defaults check box if you want to generate stub code for the expected return value.

  7. Click the OK button. Alternatively, click the Cancel button to abandon your selections.

    If you click the OK button and you have not selected any methods, No methods were selected - Continue? is displayed in a message box. Click No if you want to cancel the process and return to the dialog or click Yes to continue with the generate process.

For the example in this section, the name of the test has been left as Test_CustomerService and all of the check boxes have been checked.

When the OK button is clicked, the JadeTestCase subclass, shown in the following diagram, is then generated.

In addition to the stub methods for each of the methods defined in the Web service, a create method and a customerService property that references the Web service are also generated.

The value of the customerService property is initialized in the create method to the Web service from which the test was generated.

The code that was generated for the getCustomer method is shown in the following diagram.

In this code:

As this is a stub method only, running this test without any modifications is not likely to work; for example, pressing F9 on the method in this example to run the test results in the failed results shown in the following diagram.

The first assert fails because the expected value does not match the return value.

The second assert always fails. When the test has been coded correctly, this assert should be removed. For example, if you want this test to check that the customerNumber property in the Customer object returned by the Web service is the same as the requested number, the following diagram shows the required method modifications.

Note that the last assert has been removed and that customer number 100 has been set up. The result of running this modified test is shown in the following diagram.

Similarly, you can set up other expected values and compare these to the return values.

For details about the Unit Test Runner dialog, see the "Using the Unit Test Runner Dialog", later in this chapter.

It makes sense to compare primitive type values only, as returned object instances will not match because they will always be different (transient) object instances.