Application Development 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: 

ABAP Unit - measuring code coverage for global class with local test class

former_member182670
Contributor
0 Kudos

Hi,

Did anyone of you succeed in measuring code coverage for ABAP Unit tests created as local test classes for a global class?

It works fine when it create unit tests as local classes in reports but in SE24 I always get empty results.

My scenario is:

1. Create Global class ZCL1, add method A

2. Create local test class in ZCL1 add add a test case which examines ZCL1-A

3. In ABAP unit browser execute UT with measuring coverage

Result: coverage for ZCL1-A always shows as 0 (zero). I can see results from some system classes but not from ZCL1.

So in general measurement works but somehow omits ZCL1.

Some interesting observations:

- when I display details of coverage for ZCL1-A lines are marked with blue color. Normally they apear as grean if line was hit and red when lines was not ht

- if I create another global class ZCL2 with method B and examine it from local test class of ZCL1 then coverage results show hits for ZCL2-B but ZCL1-A has 0 hits.

- creating local test class in ZCL2 and examining ZCL2-B also doesn't bring any results

Looks like there is some issue with coverage for the class when runing it from own local test class.

Am I missing something or it's a bug?

I couldn't find any relevant notes.

Tomek

5 REPLIES 5

former_member183804
Active Contributor
0 Kudos

Hello Tomek,

sounds like a possible bug within the ABAP Unit Coverage measurement. Which netweaver release/sp are you using?

Best Regards

Klaus

0 Kudos

It's SAP_ABA release 702 SP level 0006.

Some additional info:

- when I execute tests by going to ABAP Unit Browser and selecting class pool + single class coverage results are 0,00 for my class all the time

- if I add my class to favorites and set favorites property 'With Coverage measurement' then results are 0,00 for the first run but they show correctly when I rerun the suite. Results are showing until I execute other favorite or open new internal session. Then again I get 0,00.

0 Kudos

Hello Thomek,

that should do. I can imagine only 2 possible reasons:

Is the program getting some kind of direct/indirect update

In case a program is getting some kind of update, e.g. a ddic element the programs is using gets altered, than the coverage results get invalidated/reset. Especially for test classes there is an additional constraint. The byte code of the tests is only generated on demand. That means the byte code of the program under test gets generated explicitly by ABAP Unit short before the test methods shall get invoked. Forced Byte Code Generation also has influence to the meta data of the coverage analyzer. In case the program gets touched (a new changed on time stamp) within the unit test, then coverage measurement via the ABAP Unit browser is not possible in this setup,

A possible cure might be to define in server profile (the file on the harddisk of the server°) following parameter value

abap/test_Generation = ON. This will cause that after a server restart all program generations will implicitly happen with byte code for tests

Is the execution mode "with separate external session

The combination of external session and coverage have proven recently to bear some handicaps. Most likely this combination will get disabled in a future SP. In case "separate session" has been chosen in the options of the favorite please change it to "internal session with runtime protection".

In case all sounds weird a ticket on BC-DWB-TOO-UT might be desirable.

Regards

Klaus

0 Kudos

Hello,

Reg 1. Is the program getting some kind of direct/indirect update

I can repro this using very simple test classes which don't do any updates.

Reg 2. Is the execution mode "with separate external session

My setting was "internal session with runtime protection". I tried also the others but with the same result.

Definitively there is some kind of problem with the coverage for the code which is in the same compilation unit as the test class.

It doesn't work even for the reports which have local test classes.

In the coverage results screen when I change filter in the upper grid to 'No Filter' is see the results for all kind of SAP and Z* programs except the one which contained the local test class. This one is always 0,00.

If I drill down to statement coverage for this program and display the source there are lines marked with blue color.

If I place cursor over such line there is a tool-tip "Statement #xxx "

For the other programs color is green and the tooltip Statement #xxx "

Do you know what the blue color means?

I think I will file a message anyway.

0 Kudos

Any news here?

I was currently experiencing the same issues (on 7.02.09), but discovered the following behaviour:

- Created a favorite and added my class(-pool) with local test classes in the ABAP Unit Browser.

- Execute this favorite with coverage measurement

- Result for the class under test: 0%, result for the exception class it uses: 100%

I was not able to get any results this way, until.... I browsed through the favorite's object hierarchy in the right panel to the Unit Test Class. Right-click that and choose 'Execute single test class' and bam! I got results for my class under test!

Questions that arise:

- What is causing this behaviour?

- How will we ever be able to get results by executing the entire favorite, because the procedure above is unworkable once you have a lot of local test classes?

Hope this helps others.

Kind regards,

Pascal