Wednesday, 28 April 2021 15:38

Do Unit Tests Exist?

Written by Enno Wulff
Rate this item
(0 votes)
Source https://blogs.sap.com/2021/04/29/do-unit-tests-exist/
“© 2020. SAP SE or an SAP affiliate company. All rights reserved.” “Used with permission of SAP SE”

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.

Continue reading here
Read 66 times

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.