Show TOC Start of Content Area

This graphic is explained in the accompanying text Writing Test Code  Locate the document in its SAP Library structure

A portal component providing testing code must implement the ITestable interface and implement the getTestName() method.

Syntax

public class MyAbstractPortalComponent

   extends AbstractPortalComponent

   implements ITestable {

  

   public String getTestName() {

      return "My test case";

   }

   ...

}

You can code several test case methods in a single portal component. All test methods must stick to the following pattern (where XXX can be any string supported by Java):

Syntax

public void testXXX(

   IPortalComponentRequest request,

   IPortalComponentTestResponse response) {

   ...

   }

Example

Example

public void testMode(

   IPortalComponentRequest request,

   IPortalComponentTestResponse response) {

   // ... CODING GOES HERE ...

   INode node = request.getNode();

   NodeMode nodeMode = node.getNodeMode();

   response.assert(nodeMode != INode.EDIT, "EDIT Mode not set!", "");

}

The method expects two parameters:

·        A regular implementation of IPortalComponentRequest

·        A response enriched with test-specific methods.

IPortalComponentTestResponse interface:

public interface IPortalComnponentTestResponse {

   public void assert(boolean condition, String msgLog, String msgId);

   public void verify(boolean status, String msgLog, String msgId);

   public void verify(

      boolean status,

      String msgLog,

      Exception e,

      String msgId);

   public void log(String msgLog, String msgId);

}

The assert() method checks the condition. If the condition is false the test case will show up as an error in the test result. The assert() method interrupts the test case at the first error.

The verify() method does the same but does not interrupt the test case. This allows you to put several checks in a single test case.

Example

public void testMode(

   IPortalComponentRequest request,

   IPortalComponentTestResponse response) {

   //...CODING GOES HERE...

   INode node = request.getNode();

   Response.verify(node != null, "Node is null", "");

 

   NodeMode nodeMode = node.getNodeMode();

   response.assert(nodeMode != INode.EDIT, "EDIT Mode not set!", "");

}

You can use the log() method to write additional information to the PortalComponentTestResponse. This information will be included in the test result.

Source Compilation Information

The PRT Test Framework is an extension of the PRT API. The whole Test Framework API is delivered in the prttest.jar library.

Impact on Performance

It is important to understand that you can enrich the portal application with test cases very easily and without any impact on performance. The test cases are executed only when the portal component is invoked using the test mode. This information is provided using specific URL parameters.

 

End of Content Area