eclemma branch coverage for switch: 7 of 19 missed

后端 未结 2 1969
悲&欢浪女
悲&欢浪女 2020-12-10 01:09

I have this switch system and I\'m using eclemma to test the branch coverage. We are required to have at least 80% in branch coverage for everything so I\'m trying to test a

2条回答
  •  心在旅途
    2020-12-10 02:04

    Check out the following Link: http://sourceforge.net/p/eclemma/discussion/614869/thread/80e770df/

    Below is snippet from the above link:

    This for an example having a switch with 3 cases:

    This is quite an interesting observation. From looking at the byte code one can see how the Java compiler handles the switch on strings. Actually it is an 3-step process:

    1. Switch on the hash code (3 Branches, 1 Default)
    2. For each hash code do an equals (3 * 2 branches)
    3. Do an final switch for the actual execution of the cases (3 Branches, 1 Default)

    So we have an total of 14 branches which looks strange from the source code's point of view. What looks even more strange is that you're missing three of them. The explanation is step 2 where the equals method is applied additionally after the hash code. To cover these branches also you would need to find other strings with the same hash code. This is definitely something that might be filtered from coverage reports in future versions of JaCoCo:
    https://sourceforge.net/apps/trac/eclemma/wiki/FilteringOptions

提交回复
热议问题