Correct unit test cheat sheet
This commit is contained in:
@@ -64,7 +64,7 @@ Test classes ...
|
||||
|
||||
The skeleton of a test class might look like this:
|
||||
``` abap
|
||||
"This code
|
||||
"Test class in the test include
|
||||
CLASS ltc_test_class DEFINITION
|
||||
FOR TESTING "Defines a class to be used in ABAP Unit
|
||||
RISK LEVEL HARMLESS "Defines risk level, options: HARMLESS/CRITICAL/DANGEROUS
|
||||
|
||||
@@ -325,6 +325,8 @@ CLASS zcl_demo_abap_unit_test IMPLEMENTATION.
|
||||
METHOD get_common_div_and_gcd.
|
||||
"Calculates the common divisors and the greatest common divisor of two numbers
|
||||
|
||||
CLEAR: common_divisors, gcd.
|
||||
|
||||
CHECK a >= 1.
|
||||
CHECK b >= 1.
|
||||
|
||||
@@ -364,6 +366,8 @@ CLASS zcl_demo_abap_unit_test IMPLEMENTATION.
|
||||
METHOD get_digit_sum.
|
||||
"Calculates the digit sum of a number
|
||||
|
||||
CLEAR digit_sum.
|
||||
|
||||
CHECK num >= 0.
|
||||
|
||||
DATA(converted_int) = CONV string( num ).
|
||||
|
||||
@@ -383,21 +383,13 @@ CLASS ltc_test_dummy DEFINITION FOR TESTING
|
||||
|
||||
PRIVATE SECTION.
|
||||
|
||||
DATA: ref_cut TYPE REF TO zcl_demo_abap_unit_test.
|
||||
|
||||
METHODS: test_multiple_asserts_ok FOR TESTING,
|
||||
test_multiple_asserts_fail FOR TESTING,
|
||||
setup.
|
||||
test_multiple_asserts_fail FOR TESTING.
|
||||
|
||||
ENDCLASS.
|
||||
|
||||
CLASS ltc_test_dummy IMPLEMENTATION.
|
||||
|
||||
METHOD setup.
|
||||
"Creating an object of the class under test
|
||||
ref_cut = NEW #( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD test_multiple_asserts_ok.
|
||||
"This method does not test a method of the class under test.
|
||||
|
||||
@@ -614,7 +606,7 @@ CLASS ltc_test_doc_seam IMPLEMENTATION.
|
||||
num1 = DATA(num1)
|
||||
num2 = DATA(num2) ).
|
||||
|
||||
"AssertionS
|
||||
"Assertions
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = occupancy_rate
|
||||
exp = expected_occupancy_rate
|
||||
|
||||
Reference in New Issue
Block a user