Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
ennowulff
Active Contributor
This is not a philsophical question... 😋

For internal audits or just for curiosity reasons you might want to know if there are unit tests defined in a class. Of course you can open the class and check but you might not want to regulary check several classes again and again.

The following code selects all desired classes and displays the local test classes and their unit tests:
REPORT.

TYPES: BEGIN OF _test_class,
classname TYPE seoclsname,
testclass TYPE seoclsname,
unit_test TYPE seocpdname,
END OF _test_class,
_test_classes TYPE STANDARD TABLE OF _test_class WITH EMPTY KEY.
DATA test_classes TYPE _test_classes.
DATA test_class TYPE _test_class.

SELECT-OPTIONS clsnam FOR test_class-classname DEFAULT 'CL_AUNIT*' OPTION CP OBLIGATORY.

START-OF-SELECTION.

"read classes to check
SELECT * FROM seoclass
INTO TABLE @DATA(clt)
WHERE clsname IN @clsnam.

LOOP AT clt INTO DATA(cls).
test_class-classname = cls-clsname.

"get test classes and their unit tests
DATA(hlp) = NEW cl_aunit_factory( ).
DATA(res) = hlp->get_test_class_handles(
EXPORTING
obj_type = 'CLAS'
obj_name = CONV #( cls-clsname ) ).

LOOP AT res INTO DATA(tcl).
test_class-testclass = tcl->get_class_name( ).
LOOP AT tcl->get_test_methods( ) INTO test_class-unit_test.
APPEND test_class TO test_classes.
ENDLOOP.
ENDLOOP.
ENDLOOP.


TRY.
"display found classes
cl_salv_table=>factory(
IMPORTING
r_salv_table = DATA(grid) " Basis Class Simple ALV Tables
CHANGING
t_table = test_classes ).
grid->get_functions( )->set_all( ).
grid->display( ).
CATCH cx_salv_msg INTO DATA(msg).
MESSAGE msg TYPE 'I'.
ENDTRY.

Result


12 Comments