I am not sure whether I understood the question correctly, but you can most certainly include unit tests in ABAP programs, e.g. report programs. Include the below code in a report program, then compile it.
Afterward, when you go to the Object List (Ctrl+Shift+F5 to show), you can right-click on your program, then choose Execute -> Unit Tests
from the menu.
The important part is that unit tests are marked as FOR TESTING
and have at least one method marked FOR TESTING
as well. The RISK LEVEL
addition will also determine whether, according to the system settings, a test is allowed to run. (Hit F1 on the keyword in the editor to read more).
* The following defines a unit test class
class unit_tests definition for testing risk level harmless.
public section.
methods: test_query for testing.
endclass.
class unit_tests implementation.
method test_query.
data: lv_result type string.
perform execute_query_b using '123' changing lv_result.
assert lv_result = 'Expected_value'.
endmethod.
endclass.
* Here is a subroutine in our program we wish to test
form execute_query_b using a changing res.
res = 'Expected_value'.
endform.