2009 Jul 22 1:31 PM
Hi all
I had written a test code of abap, it is for test a form of abap pgm.
Now , I want to know the percent of coverage about this test code. How should I do.
For example:
This is my abap pgm.
FORM GET_LFG USING VALUE(L_AGE) TYPE N
CHANGING L_FLG TYPE N
IF L_AGE > 60.
L_FLG = 1.
ELSEIF L_AGE >= 40 AND L_AGE <= 60.
L_FLG = 2.
ELSE.
L_FLG = 3.
ENDIF.
ENDFORM.
This is my test code.
----
CLASS lcl_test DEFINITION
----
CLASS LCL_TEST DEFINITION FOR TESTING "#AU Duration Short
INHERITING FROM CL_AUNIT_ASSERT. "#AU Risk_Level Harmless
PRIVATE SECTION.
METHODS TEST_GET_LFG_SIMPLE_CALL FOR TESTING.
ENDCLASS. "lcl_test DEFINITION
----
CLASS lcl_test IMPLEMENTATION
----
CLASS LCL_TEST IMPLEMENTATION.
METHOD TEST_GET_LFG_SIMPLE_CALL.
Setup parameters for the call...
DATA :
L_AGE(2) TYPE N,
L_FLG TYPE N.
Perform the call
L_AGE = 61.
PERFORM GET_AGE USING L_AGE
CHANGING L_FLG.
Check returned values
ASSERT_EQUALS( ACT = L_FLG EXP = 1 MSG = 'ERROR FOR OVER 60 YEARS' ).
Perform the call
L_AGE = 55.
PERFORM GET_AGE USING L_AGE
CHANGING L_FLG.
Check returned values
ASSERT_EQUALS( ACT = L_FLG EXP = 2 MSG = 'ERROR FOR FORM 40 TO 60 YEARS' ).
ENDMETHOD. "TEST_GET_GLE_SIMPLE_CALL
ENDCLASS. "lcl_test IMPLEMENTATION
The test code just check two cases. the other case(<40) is not be tested.
thanks
ljz
Hi all
I had written a test code of abap, it is for test a form of abap pgm.
Now , I want to know the percent of coverage about this test code. How should I do.
For example:
This is my abap pgm.
FORM GET_LFG USING VALUE(L_AGE) TYPE N
CHANGING L_FLG TYPE N
IF L_AGE > 60.
L_FLG = 1.
ELSEIF L_AGE >= 40 AND L_AGE <= 60.
L_FLG = 2.
ELSE.
L_FLG = 3.
ENDIF.
ENDFORM.
This is my test code.
----
CLASS lcl_test DEFINITION
----
CLASS LCL_TEST DEFINITION FOR TESTING "#AU Duration Short
INHERITING FROM CL_AUNIT_ASSERT. "#AU Risk_Level Harmless
PRIVATE SECTION.
METHODS TEST_GET_LFG_SIMPLE_CALL FOR TESTING.
ENDCLASS. "lcl_test DEFINITION
----
CLASS lcl_test IMPLEMENTATION
----
CLASS LCL_TEST IMPLEMENTATION.
METHOD TEST_GET_LFG_SIMPLE_CALL.
Setup parameters for the call...
DATA :
L_AGE(2) TYPE N,
L_FLG TYPE N.
Perform the call
L_AGE = 61.
PERFORM GET_AGE USING L_AGE
CHANGING L_FLG.
Check returned values
ASSERT_EQUALS( ACT = L_FLG EXP = 1 MSG = 'ERROR FOR OVER 60 YEARS' ).
Perform the call
L_AGE = 55.
PERFORM GET_AGE USING L_AGE
CHANGING L_FLG.
Check returned values
ASSERT_EQUALS( ACT = L_FLG EXP = 2 MSG = 'ERROR FOR FORM 40 TO 60 YEARS' ).
ENDMETHOD. "TEST_GET_GLE_SIMPLE_CALL
ENDCLASS. "lcl_test IMPLEMENTATION
The test code just check two cases. the other case(<40) is not be tested.
thanks
ljz
2009 Jul 26 2:05 PM
2009 Jul 27 2:25 AM
I have not used the tools yet, but you might want to try the runtime monitor (transaction SRTM) or the coverage analyser (transaction SCOV) for segment coverage.
best regards,
J. Nomssi N.
2009 Aug 05 4:54 PM
Hello Lhz,
from netweaver release 7.02 onwards unit test execution with combined coverage measurement is integrated into the IDE (transaction SE80). For the older releases these are seperate tools. In case you are in your development system the follwoing approach may help.
Any code change to your report will also reset any coverage measurement (TA SCOV).
After a change execute your unit tests and review the effects in transaction SCOV. Please note that SCOV needs to be switch on explictely and that the so called data collection of SCOV happens not event based but on regular schedule. This can delay the arrival of your actions in the coverage results.
Kind Regards
Klaus
2009 Aug 05 5:01 PM
As Klaus suggested, you can use the Coverage Analyzer to know the Coverage of your ABAP Unit Test.
Check this link:
http://help.sap.com/saphelp_nwpi71/helpdata/en/44/a7ed075c1a5e77e10000000a155369/frameset.htm
Regards,
Naimesh Patel
2009 Aug 06 1:43 PM
hi ,all
thanks your advices. I am having to use scov. If I got some result, I will share it.
2009 Aug 06 8:35 PM
We have been wondering the same thing at my company. SCOV gives us some data to start with but is generally a pain to set up and to focus on a specific piece of code that we are currently developing.
I have read that 7.02 will have some more robust features as it pertains to code coverage and we look forward to that. If anyone else has another way to calculate code coverage based on unit testing I would appreciate any information you can provide.
Andy
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |