‎2022 Jun 02 9:14 AM
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!
‎2022 Jun 07 8:46 AM
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
‎2022 Jun 02 12:31 PM
Searchable sentence:
ABAP Doc syntax "@testing" can reference main objects outside their own program only.
‎2022 Jun 02 12:32 PM
I guess you mean it works for tested methods which are public, but not for those which are private.
‎2022 Jun 02 12:49 PM
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 🙂
‎2022 Jun 02 12:58 PM
Maybe nobody has manage the case of private method, because you must not test private method.
‎2022 Jun 04 4:22 PM
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.
‎2022 Jun 07 8:46 AM
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