Missing branches when using assertTrue instead of assertNull

后端 未结 3 997
太阳男子
太阳男子 2020-12-30 04:14

In Java/Junit, I need to test for null with some object. There are a variety of ways I can test a condition but I have been using assertTrue for most of my tests. When I c

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-30 04:57

    The fact that Emma treats a conditional expression as "something with a branch" for (branch) coverage counting IMHO seems simply broken. It isn't a conditional branch.

    We can argue more about the Assert; if it were defined as "throws exception on assert failure" then it really does have a conditonal branch; if it is defined [as I think i does, I'm not a Java expert] as "terminate my program on assert failure" then it isn't really a branch. Also obscure are method calls; these are conditional branches in the sense that if the called method throws an exception, control flow does not continue to the "rest of the statement".

    Our Java Test Coverage tool gets the (branch) coverage analysis on such conditionals "right".

提交回复
热议问题