Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boolean Assert in ABAP Unit

How do I write a simple ABAP Unit Assert statement to check if any call, expression or other statement evaluates to true?

I can't see any basic assert() or assert_true() methods in CL_AUNIT_ASSERT while I'd expect those to be very common. I can approximate such an assert as follows, but is there no cleaner way?

cl_aunit_assert=>assert_equals(
  act = boolc( lv_value > 100 OR lv_value < 2 )
  exp = abap_true ).

cl_aunit_assert=>assert_equals(
  act = mo_model->is_active )
  exp = abap_true ).
like image 619
Lilienthal Avatar asked Jan 10 '23 18:01

Lilienthal


1 Answers

Depending on your SAP NetWeaver stack you can (or should) use the updated ABAP Unit Class CL_ABAP_UNIT_ASSERT. This class is available at a Basis-Release >= 7.02. SAP declared this class as 'FINAL' so it´s impossible to inherit from it, but on the other side they added some ASSERT-Methods like the ASSERT_TRUE Method!

Here is a possible usage of this method:

cl_abap_unit_assert=>assert_true(
  exporting
    act = m_ref_foo->is_bar( l_some_var )
    msg = 'is_bar Method fails with Input { l_some_var }'
).
like image 122
Damir Avatar answered Mar 03 '23 13:03

Damir