Unit testing code coverage - do you have 100% coverage?

后端 未结 17 2723
离开以前
离开以前 2020-12-13 09:05

Do your unit tests constitute 100% code coverage? Yes or no, and why or why not.

17条回答
  •  攒了一身酷
    2020-12-13 09:28

    I usually manage to hit 93..100% with my coverage but I don't aim for 100% anymore. I used to do that and while it's doable, it's not worth the effort beyond a certain point because testing blindly obvious usually isn't needed. Good example of this could be the true evaluation branch of the following code snipped

    public void method(boolean someBoolean) {
        if (someBoolean) {
            return;
        } else {
            /* do lots of stuff */ 
        }
    }
    

    However what's important to achieve is to as close to 100% coverage on functional parts of the class as possible since those are the dangerous waters of your application, the misty bog of creeping bugs and undefined behaviour and of course the money-making flea circus.

提交回复
热议问题