Figure 1
Figure 2
Figure 3
Figure 4 : Click on create button and provide test class name. Select all options to generate predefined methods.
Figure 5 : Select the methods for which we want to generate test class.
Figure 6 : Test class generation is completed.
class ltc_Unit_Test_Class_Demo1 definition for testing
duration short
risk level harmless.
*?<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
*?<asx:values>
*?<TESTCLASS_OPTIONS>
*?<TEST_CLASS>ltc_Unit_Test_Class_Demo1
*?</TEST_CLASS>
*?<TEST_MEMBER>f_Cut
*?</TEST_MEMBER>
*?<OBJECT_UNDER_TEST>ZCL_UNIT_TEST_CLASS_DEMO1
*?</OBJECT_UNDER_TEST>
*?<OBJECT_IS_LOCAL/>
*?<GENERATE_FIXTURE>X
*?</GENERATE_FIXTURE>
*?<GENERATE_CLASS_FIXTURE>X
*?</GENERATE_CLASS_FIXTURE>
*?<GENERATE_INVOCATION>X
*?</GENERATE_INVOCATION>
*?<GENERATE_ASSERT_EQUAL>X
*?</GENERATE_ASSERT_EQUAL>
*?</TESTCLASS_OPTIONS>
*?</asx:values>
*?</asx:abap>
private section.
data:
f_Cut type ref to zcl_Unit_Test_Class_Demo1. "class under test
class-methods: class_Setup.
class-methods: class_Teardown.
methods: setup.
methods: teardown.
methods: read_Bom_Version for testing.
endclass. "ltc_Unit_Test_Class_Demo2
class ltc_Unit_Test_Class_Demo1 implementation.
method class_Setup.
endmethod.
method class_Teardown.
endmethod.
method setup.
create object f_Cut.
endmethod.
method teardown.
endmethod.
method read_Bom_Version.
data is_Mass_Det type mpes_Majorassembly.
data is_Rcnip01 type rcnip01.
data ev_Bom_Ver type cs_Versn.
data et_Bom_Ver type zcl_Unit_Test_Class_Demo1=>tt_Bom_Ver.
f_Cut->read_Bom_Version(
EXPORTING
IS_MASS_DET = is_Mass_Det
IS_RCNIP01 = is_Rcnip01
* IMPORTING
* EV_BOM_VER = ev_Bom_Ver
* ET_BOM_VER = et_Bom_Ver
).
cl_Abap_Unit_Assert=>assert_Equals(
act = ev_Bom_Ver
exp = ev_Bom_Ver "<--- please adapt expected value
" msg = 'Testing value ev_Bom_Ver'
* level =
).
cl_Abap_Unit_Assert=>assert_Equals(
act = et_Bom_Ver
exp = et_Bom_Ver "<--- please adapt expected value
" msg = 'Testing value et_Bom_Ver'
* level =
).
endmethod.
endclass.
Figure 7
Figure 8 : Test environment for DB artifact redirection
Figure 9
Figure 10: Use of Test environment in UTC
Figure 11
Figure 12 : Use of Test-Seam--End-Test-Seam in class method.
Figure 13 : Use of Test-Injection--End-Test-Injection in UTC.
*"* use this source file for your ABAP unit test classes
CLASS ltc_unit_test_class_demo1 DEFINITION DEFERRED.
CLASS zcl_unit_test_class_demo1 DEFINITION LOCAL FRIENDS ltc_unit_test_class_demo1.
CLASS ltc_unit_test_class_demo1 DEFINITION FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
PRIVATE SECTION.
DATA: f_cut TYPE REF TO zcl_unit_test_class_demo1. "class under test
CLASS-DATA : environment TYPE REF TO if_osql_test_environment.
CLASS-METHODS: class_setup.
CLASS-METHODS: class_teardown.
METHODS: setup.
METHODS: teardown.
METHODS: read_bom_version_if FOR TESTING.
METHODS: read_bom_version_else FOR TESTING.
ENDCLASS. "ltc_Unit_Test_Class_Demo1
CLASS ltc_unit_test_class_demo1 IMPLEMENTATION.
METHOD class_setup.
environment = cl_osql_test_environment=>create( i_dependency_list = VALUE #( ( 'MAST' ) ( 'STZU' ) ( 'STKO' ) ) ).
ENDMETHOD.
METHOD class_teardown.
ENDMETHOD.
METHOD setup.
CREATE OBJECT f_cut.
ENDMETHOD.
METHOD teardown.
ENDMETHOD.
METHOD read_bom_version_if.
DATA: is_mass_det TYPE mpes_majorassembly,
is_rcnip01 TYPE rcnip01,
lv_bom_ver TYPE cs_versn ##NEEDED,
lt_bom_ver TYPE zcl_unit_test_class_demo1=>tt_bom_ver,
lt_mast_bm TYPE TABLE OF mast,
lt_stzu_bm TYPE TABLE OF stzu,
lt_stko_bm TYPE TABLE OF stko.
is_mass_det = VALUE #( matnr = 'MAJOR_ASMBLY03' plant = '0001' stlal = '01').
is_rcnip01 = VALUE #( stlan = 'V' ).
lt_mast_bm = VALUE #( ( matnr = 'MAJOR_ASMBLY03' werks = '0001'
stlnr = '89876' stlan = 'V' stlal = '01' ) ).
lt_stzu_bm = VALUE #( ( stlty = 'M' stlnr = '89876' versnind = 'X' ) ).
lt_stko_bm = VALUE #( ( stlty = 'M' stlnr = '89876' versnst = '99' bom_versn = '0001') ).
environment->insert_test_data( lt_mast_bm ).
environment->insert_test_data( lt_stzu_bm ).
environment->insert_test_data( lt_stko_bm ).
f_cut->read_bom_version(
EXPORTING
is_mass_det = is_mass_det
is_rcnip01 = is_rcnip01
IMPORTING
ev_bom_ver = lv_bom_ver
et_bom_ver = lt_bom_ver ).
"Checking the method
cl_abap_unit_assert=>assert_not_initial(
act = lt_bom_ver
msg = 'Testing Read BOM Version Failed' ).
ENDMETHOD.
METHOD read_bom_version_else.
DATA: is_mass_det TYPE mpes_majorassembly,
is_rcnip01 TYPE rcnip01,
lv_bom_ver TYPE cs_versn ##NEEDED,
lt_bom_ver TYPE zcl_unit_test_class_demo1=>tt_bom_ver,
lt_mast TYPE TABLE OF mast,
lt_stzu TYPE TABLE OF stzu,
lt_stko TYPE TABLE OF stko.
is_mass_det = VALUE #( matnr = 'MAJOR_ASMBLY1' plant = '0001' stlal = '01').
is_rcnip01 = VALUE #( stlan = 'V' ).
lt_mast = VALUE #( ( matnr = 'MAJOR_ASMBLY1' werks = '0001' stlnr = '89878' stlan = 'V' stlal = '01' )
( matnr = 'MAJOR_ASMBLY1' werks = '0001' stlnr = '234561' stlan = 'V' stlal = '01' ) ).
lt_stzu = VALUE #( ( stlty = 'M' stlnr = '89878' versnind = 'X' )
( stlty = 'M' stlnr = '234561' versnind = 'X' ) ).
lt_stko = VALUE #( ( stlty = 'M' stlnr = '89878' versnst = '01' bom_versn = '0001')
( stlty = 'M' stlnr = '234561' versnst = '99' bom_versn = '0002') ).
environment->insert_test_data( lt_mast ).
environment->insert_test_data( lt_stzu ).
environment->insert_test_data( lt_stko ).
f_cut->read_bom_version(
EXPORTING
is_mass_det = is_mass_det
is_rcnip01 = is_rcnip01
IMPORTING
ev_bom_ver = lv_bom_ver
et_bom_ver = lt_bom_ver ).
"Checking the method
cl_abap_unit_assert=>assert_not_initial(
act = lt_bom_ver
msg = 'Testing Read BOM Version Failed' ).
ENDMETHOD.
ENDCLASS.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |