Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABAP Docs for Testing relations addressing private methods

schmelto
Active Participant
0 Likes
3,148

What is the best practice for linking to test relations for private methods.

For example I have a ABAP Class with some private methods.

PRIVATE SECTION.
METHODS set_remittance_vend_reference
[...]

And in my test class I want to link the Unit Test method to the method in the main class.

"! <p class="shorttext synchronized">Test for set_remittance_vend_reference</p>
"! @testing zcl_fi_edi_payext_2441.METH:set_remittance_vend_reference
set_remittance_vend_reference FOR TESTING.

For reference the test class can access private methods of the main class with `LOCAL FRIENDS `

The above seen ABAP Doc will throw following warning message:

Is there a way to exclude this warning due the Method is "correctly" linked to the method in the main program.

Thanks!

1 ACCEPTED SOLUTION
Read only

2,880

Hi Tom,

just to summarize: What you want to do is not possible. The @testing annotation has been designed to refer from a test class or test method to other repository objects (class, cds view, etc.) that are being tested.

For classes that contain their tests in the test class include, @testing is not needed.

Furthermore @testing cannot refer to a method, neither public nor private.

Regards,
Michael

6 REPLIES 6
Read only

Sandra_Rossi
Active Contributor
2,880

Searchable sentence:

ABAP Doc syntax "@testing" can reference main objects outside their own program only.

Read only

Sandra_Rossi
Active Contributor
2,880

I guess you mean it works for tested methods which are public, but not for those which are private.

Read only

schmelto
Active Participant
0 Likes
2,880

it also kind of works for private methods in the main class. When I click on the link the right method will be displayed in the ABAP Element info but the warning in eclipse is there.

So I wondered if expect the warning that only public methods can be accessed there is a good way to reference to those methods.

Otherwise I do not understand the usage of @testing 🙂

Read only

FredericGirod
Active Contributor
2,880

Maybe nobody has manage the case of private method, because you must not test private method.

Read only

pokrakam
Active Contributor
2,880

Two comments:

The message is correct, `@testing` is intended for external reference. Given that you use LOCAL FRIENDS, I assume your test class is local to the main class. `@testing` doesn't make sense here, because a local test is automatically associated with its global class. The directive is intended for remote references, i.e. if one global class tests another global class.

See this blog for more info: https://blogs.sap.com/2020/12/07/abap-unit-test-relations/

Secondly, as Frederic already suggested, it is best to test a class only via its public interface. Testing private methods makes your tests brittle and the main class difficult to refactor.

Read only

2,881

Hi Tom,

just to summarize: What you want to do is not possible. The @testing annotation has been designed to refer from a test class or test method to other repository objects (class, cds view, etc.) that are being tested.

For classes that contain their tests in the test class include, @testing is not needed.

Furthermore @testing cannot refer to a method, neither public nor private.

Regards,
Michael