Q: 8
In a test method you call method cl_abap_unit_assert=>assert_equals( .. ) in the following way:
CLASS Itcl1 DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PRIVATE SECTION.
METHODS m1 FOR TESTING.
ENDCLASS.
CLASS Itcl1 IMPLEMENTATION.
METHOD m1.
DATA: go_test_object TYPE REF TO zcl_to_be_tested.
CONSTANTS: Ico_exp TYPE string VALUE 'test2'.
CREATE OBJECT go_test_object.
cl_abap_unit_assert=>assert_equals(
EXPORTING
act = go_class->mv_attribute
exp = lco_exp
msg = 'assert equals failed ' && go_test_object->mv_attribute && ' ' && lco_exp
ENDMETHOD.
ENDCLASS.
What will happen if method parameters act and exp are not equal?
Options
Discussion
Don't think C is right here. D is the way ABAP Unit handles failed assertions, it just adds a message to the log. C seems like a common confusion, but it doesn't abort everything. Agree?
D , only see the failure in the test log if act and exp aren't equal.
D imo, ABAP Unit just puts the failure and your custom msg in the test log, it doesn't stop the whole test run. I've seen C trip people up since it feels like an abort, but it's not for all tests. Open to corrections on edge cases.
C seems reasonable, because when assert_equals fails the current method stops running. I think a lot of people get tricked by this vs the full test suite, but C matches similar question logic I've seen.
C/D? In practice, the current test method stops, but only D is logged for review, so depends how nitpicky you read it.
I don’t think it’s C. D makes more sense since a failed assert just logs the error in the test log, it doesn’t stop all tests. That’s pretty standard for ABAP Unit. Unless I’m missing something?
Had something like this in a mock, went with D.
C tbh, feels like a failed assert aborts the test method so it fits. D looks like a trap option here.
Maybe C since a failed assertion usually means the current test method stops executing, so it could be considered "aborted" for that specific method. But the whole suite still runs, so not totally sure if that's right here. Anyone else thinking C makes sense?
D imo. If the values don't match, you'll just get a failure message in the test log, nothing more disruptive.
Be respectful. No spam.