Skip to Content

Testing private methods: Declaring a local test friend

I try to test the private methods of a class and therefor I declare a local test friend following this scheme:

class lcl_test definition deferred.
class zcl_testee definition local friends lcl_test.
...
class lcl_test definition for testing ...
...

This is been discussed in this wiki article or in this blog entry.

But all I get is the syntax error "The statement CLASS is unexpected".

What is wrong here?

My complete code:

CLASS lcl_test DEFINITION DEFERRED.
CLASS zcl_testee DEFINITION
 PUBLIC FINAL CREATE PUBLIC .
  PUBLIC SECTION.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS zcl_testee IMPLEMENTATION.
ENDCLASS.

CLASS lcl_test DEFINITION.
ENDCLASS.

CLASS lcl_test IMPLEMENTATION.
ENDCLASS.
Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Sep 13, 2017 at 05:40 AM

    Take my classes of package SABAP_DEMOS_CAR_RENTAL_APPL as an example, e.g. CL_DEMO_CR_RESERVATION_CATA. Check the includes where the test classes reside and where they are declared DEFERRED and as friends (local definitions and implementations).

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 12, 2017 at 09:33 PM

    Where are you writing the code, report or class?

    If report, then your class cannot be public. If it's in a class then the unit test class must be in the local test classes section, tab at the bottom of your editor if you use Eclipse, somewhere in the menu if you use SE24/80.

    The all the code in your first block goes in the unit test section. The design here is that it doesn't even get compiled in a productive system, hence the strong separation.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.