Skip to Content
Technical Articles
Author's profile photo Sunita Shirabadagt

Use of “INTERFACES-PARTIALLY IMPLEMENTED “

Introduction

Interface injection is one of the core concepts, used to remove ABAP dependency in unit test class. When Interface Injection is used in Unit Test Class then we need to implement ALL the available methods. This was causing the low coverage of class and also resulting  ATC(ABAP Test Cockpit)  error.

Issue

If ALL the available interface methods are not implemented, then syntax warning occurs in the test class causing ATC error in next systems.

The warning is occurring because of not implementing INF1 interface add method.

Solution

Using PARTIALLY IMPLEMENTED keyword, we can only implement those methods which are required for our UTC. This will prevent the syntax warning, if not all the interface methods are implemented in the unit test class. This keyword should be used while defining a interface as shown below.

Use the syntax

INTERFACES <interface_name> PARTIALLY IMPLEMENTED.

Example

The ltc_help_demo is the local class created in UTC to remove the dependency of the object. In the below example, Class ltc_help_demo implements the interface INF1, which is having more than 10 methods. Only 2 methods (add and sub) are required in this unit test class to execute a test scenario.

Local Class Definition:

CLASS ltc_help_demo DEFINITION FOR TESTING.

  PUBLIC SECTION.
    INTERFACES: <INF1> PARTIALLY IMPLEMENTED.
  
ENDCLASS.

 Now Implement only required methods.

CLASS ltc_help_demo IMPLEMENTATION.


  METHOD INF1~add.
  ENDMETHOD.
  METHOD INF1~sub.
  ENDMETHOD.


ENDCLASS.

 

Note

  1. PARTIALLY IMPLEMENTED keyword,  can only be used in test classes for interfaces.
  2. If an interface method, which is not implemented, is called during a test execution, an exception is raised from the class CX_SY_DYN_CALL_ILLEGAL_METHOD.

Benefit

  • It will reduce ATC error (in Development and Testing Systems) significantly.
  • It will increase lines no. of coverage.
  • It will increase coverage for number of methods.

Conclusion

Using PARTIALLY IMPLEMENTED, we can implement only required interface methods for the test. This is useful when a class implements an interface and not all the interface methods are used in the code being tested.

 

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Lars Hvam
      Lars Hvam

      Note PARTIALLY IMPLEMENTED works from 740sp02 and up

      Author's profile photo Sunita Shirabadagt
      Sunita Shirabadagt
      Blog Post Author

      Thanks for your info

      Author's profile photo Michelle Crapo
      Michelle Crapo

      Nice way of doing things.

      Thank you!

      Michelle

      Author's profile photo Nabheet Madan
      Nabheet Madan

      Much Needed thanks for the tip.

      Nabheet

      Author's profile photo Md Rustam Alam
      Md Rustam Alam

      Thanks for nice blog with proper example. I think, will be very useful in Unit test class development.. 🙂