04-22-2009 8:46 PM
Hi,
I created a small example of testing using ABAP Unit shown below.
But i get a syntax error in German, i translated to English and this is what i get
The reference to a test class (marking with FOR TESTING) is only in test classes possible
How do i resolve this?
CLASS myclass DEFINITION.
PUBLIC SECTION.
CLASS-DATA text TYPE string.
CLASS-METHODS set_text_to_x.
ENDCLASS.
CLASS myclass IMPLEMENTATION.
METHOD set_text_to_x.
text = 'U'.
ENDMETHOD.
ENDCLASS.
Test classes
CLASS mytest DEFINITION FOR TESTING.
PRIVATE SECTION.
METHODS mytest FOR TESTING.
ENDCLASS.
CLASS mytest IMPLEMENTATION .
METHOD mytest .
myclass=>set_text_to_x( ).
cl_aunit_assert=>assert_equals( act = myclass=>text
exp = 'X'
msg = 'failed').
ENDMETHOD.
ENDCLASS.
DATA my_ref TYPE REF TO mytest.
CREATE OBJECT my_ref type mytest.
call METHOD my_ref->mytest.
04-22-2009 9:01 PM
You're almost there. You don't need to create a object reference to your ABAP Unit Test class. To run the ABAP Unit test, you need to do the Program > Test > Unit Test
CLASS myclass DEFINITION.
PUBLIC SECTION.
CLASS-DATA text TYPE string.
CLASS-METHODS set_text_to_x.
ENDCLASS.
CLASS myclass IMPLEMENTATION.
METHOD set_text_to_x.
text = 'U'.
ENDMETHOD.
ENDCLASS.
* Test classes
*-------*
CLASS mytest DEFINITION FOR TESTING.
PRIVATE SECTION.
METHODS mytest FOR TESTING.
ENDCLASS.
CLASS mytest IMPLEMENTATION .
METHOD mytest .
myclass=>set_text_to_x( ).
cl_aunit_assert=>assert_equals( act = myclass=>text
exp = 'X'
msg = 'failed').
ENDMETHOD.
ENDCLASS.
Check thread
Regards,
Naimesh Patel
04-22-2009 9:01 PM
You're almost there. You don't need to create a object reference to your ABAP Unit Test class. To run the ABAP Unit test, you need to do the Program > Test > Unit Test
CLASS myclass DEFINITION.
PUBLIC SECTION.
CLASS-DATA text TYPE string.
CLASS-METHODS set_text_to_x.
ENDCLASS.
CLASS myclass IMPLEMENTATION.
METHOD set_text_to_x.
text = 'U'.
ENDMETHOD.
ENDCLASS.
* Test classes
*-------*
CLASS mytest DEFINITION FOR TESTING.
PRIVATE SECTION.
METHODS mytest FOR TESTING.
ENDCLASS.
CLASS mytest IMPLEMENTATION .
METHOD mytest .
myclass=>set_text_to_x( ).
cl_aunit_assert=>assert_equals( act = myclass=>text
exp = 'X'
msg = 'failed').
ENDMETHOD.
ENDCLASS.
Check thread
Regards,
Naimesh Patel
04-23-2009 5:47 PM
Thanks Naimesh,
but in the results all i get is "No execution as actual risk level is too high"
I tried giving the correct value X so that the test passes but i get the same thing. Is there some setting problem?
04-23-2009 6:08 PM
Hi,
I added
CLASS mytest DEFINITION FOR TESTING. "#AU Risk_Level Harmless
it worked fine.
Thanks for ur inputs.
04-22-2009 9:49 PM
Hello
Do not miss out the 5-part blog series by Thomas Weiss about ABAP Unit Testing:
[ABAP Unit Testing|https://www.sdn.sap.com/irj/sdn/abap?rid=/webcontent/uuid/e08bec4e-8c57-2910-94a8-9e94caa20bee#section26 [original link is broken]]
Regards
Uwe