Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

abap unit how to??

Former Member
0 Likes
1,530

hi

i would like to know how to create ABAP unit for the developed ABAP objects?i saw in couple of sites but unable to understand the root that is if anyone have any real time specific example or any idea on this can u throw some light on this?

i was asked to prepare couple of test cases for some objects and need some inputs on this regard.

1 ACCEPTED SOLUTION
Read only

Ruediger_Plantiko
Active Contributor
0 Likes
1,381

Hi Moorthy,

I once wrote a Wiki for ABAP Units

http://wiki.sdn.sap.com/wiki/display/ABAP/ABAP+Unit+Best+Practices

Please check it. The code template therein will help you to quickly start with ABAP unit test in your own code.

Hope it helps!

Rüdiger

hi

i would like to know how to create ABAP unit for the developed ABAP objects?i saw in couple of sites but unable to understand the root that is if anyone have any real time specific example or any idea on this can u throw some light on this?

i was asked to prepare couple of test cases for some objects and need some inputs on this regard.

7 REPLIES 7
Read only

Ruediger_Plantiko
Active Contributor
0 Likes
1,382

Hi Moorthy,

I once wrote a Wiki for ABAP Units

http://wiki.sdn.sap.com/wiki/display/ABAP/ABAP+Unit+Best+Practices

Please check it. The code template therein will help you to quickly start with ABAP unit test in your own code.

Hope it helps!

Rüdiger

Read only

0 Likes
1,381

Hi Rüdiger

I have gone through the link. can u give me some code on how u have checked the subroutine call and other tests that u have done.

i need a scenario -so that i can start developing the same for my scenario.what and how u have checked the subroutine or other fm calls.

thanks

Read only

0 Likes
1,381

Hi Moorthy,

here comes a kind of hello world version, which already shows you  some important things.

  • I don't test the report, I don't emulate input, I don't call the code at start-of-selection, I don't test the spool output (WRITE). I only test the functionality
  • For this, I have separated the functionality in a parametrized subroutine add (or method, or function module)
  • Run the unit test in SE38 with "Program -> Test -> Unit Test". There is also the option of a background run (with the code inspector), and as obstacle for release of a transport order (very useful!)
  • The more code you have, the more tests you will have. You have two players playing against each others: Your code portfolio and your test suites testing this code. Both are equally important (in earlier times, I neglected the test part and worked with throw-away tests. This was bad.)
  • Usually, each test has three parts: 1.) Setup: Prepare the data for a call. 2.) Execution: Call the module (routine/method...) 3.) Verification: The result data are as expected.

That's all. Easy, but very useful!

Regards,

Rüdiger

*&---------------------------------------------------------------------*
*& Report  ZZ_ADD_TWO_NUMBERS
*&---------------------------------------------------------------------*
report  zz_add_two_numbers.

parameters: p_first type i,
            p_second type i.

start-of-selection.

  perform start.

* --- Delegates the computational part to routine "add"
form start.
  data: lv_result type i.
  perform add using p_first p_second
              changing lv_result.
  write: / p_first, '+', p_second, '=', lv_result.
endform.                    "start

* --- Separate the computational part
form add using iv_first type i
               iv_second type i
         changing ev_result type i.
  ev_result = iv_first + iv_second.
endform.                    "add

*
class lcl_test definition for testing  " #AU Risk_Level Harmless
      inheriting from cl_aunit_assert. " #AU Duration Short

  private section.
    methods test_1_plus_1 for testing.

endclass.                    "lcl_test DEFINITION

*
class lcl_test implementation.
*
  method test_1_plus_1.
    data: lv_result type i.
    perform add using 1 1 changing lv_result.
    assert_equals( act = lv_result
                   exp = 2 ).
  endmethod.                    "test_1_plus_1
endclass.                    "lcl_test IMPLEMENTATION

Read only

0 Likes
1,381

Hi Rüdiger,

allthough this might be off topic,

I am dying to know, how you applied these nice CODE tags to your reply.

I already tried the old way ( using {code} ), but did not manage to get anything working.

The style combobox in this editor does not show a code-style, so I assume you need to do some html tricks ?

Would really appreciate a hint on how you managed that.

Thanks

Volker

Read only

0 Likes
1,381

Hello Volker,

I learned this from Suhas. The "syntax highlighting"  is available only in the "advanced editor". Above the text editor for notes, you'll find the link "use advanced editor". Follow it and continue writing in the advanced editor. There you find a button with ">>" on it. When you click it, you find out that it is a multi-select buton. Choose "Syntax highlighting", and then "plain", since there is no syntax highlighting for ABAP yet.

I think the {code} tag still exists, but you can only use it in other areas of the SCN, like e.g. wiki's.

I am not happy with the current state:

  • Every coder should know that code feels comfortable only when written in a non-proportional font.
  • There is no ABAP syntax highlighting. What a pity for an ABAP forum.

So it continues to look non-professional.

Regards,

Rüdiger

Read only

0 Likes
1,381

... oh, I forgot: And the line numbering is ****, too:

Read only

0 Likes
1,381

Thank you very much !

How bad is that. I already checked the advanced editor, but when

"hovering" above ">>" it only said "INSERT", SO I NEVER PRESSED IT!

Guess it would be helpfull if there would be a combobox arrow like near to the "Style" button.

Have to try that ...

Gotta check that out :-)

Well, linenumbering seems to work

just duplicating lines for no reason. But I'll work on that later.

Thanks a lot 😉

Volker