Testing on the Toilet

Mar. 6, 2008

Understanding Your Coverage Data Code coverage (also called test coverage) measures which lines of source code have been executed by tests. A common misunderstanding of code coverage data is the belief that: My source code has a high percentage of code coverage; therefore, my code is well-tested. The above statement is FALSE! High coverage is a necessary, but not sufficient, condition. Well-tested code =======> High coverage Well-tested code <== X === High coverage The most common type of coverage data collected is statement coverage. It is the least expensive type to collect, and the most intuitive. Statement coverage measures whether a particular line of code is ever reached by tests. Statement coverage does not measure the percentage of unique execution paths exercised. Limitations of statement coverage: • It does not take into account all the possible data inputs. Consider this code: int a = b / c; •

This could be covered with b = 18 and c = 6, but never tested where c = 0. Some tools do not provide fractional coverage. For instance, in the following code, when condition a is true, the code already has 100% coverage. Condition b is not evaluated. if (a || b) { // do something }



Coverage analysis can only tell you how the code that exists has been exercised. It cannot tell you how code that ought to exist would have been executed. Consider the following: error_code = FunctionCall(); // returns kFatalError, kRecoverableError, or kSuccess if (error_code == kFatalError) { // handle fatal error, exit } else { // assume call succeeded }

This code is only handling two out of the three possible return values (a bug!). It is missing code to do error recovery when kRecoverableError is returned. With tests that generate only the values kFatalError and kSuccess, you will see 100% coverage. The test case for kRecoverableError does not increase coverage, and appears “redundant” for coverage purposes, but it exposes the bug! So the correct way to do coverage analysis is: 1. Make your tests as comprehensive as you can, without coverage in mind. This means writing as many test case as are necessary, not just the minimum set of test cases to achieve maximum coverage. 2. Check coverage results from your tests. Find code that's missed in your testing. Also look for unexpected coverage patterns, which usually indicate bugs. 3. Add additional test cases to address the missed cases you found in step 2. 4. Repeat step 2-3 until it's no longer cost effective. If it is too difficult to test some of the corner cases, you may want to consider refactoring to improve testability. Reference for this episode: How to Misuse Code Coverage by Brian Marick from Testing Foundations.

More information, discussion, and archives: http://googletesting.blogspot.com Copyright © 2007 Google, Inc. Licensed under a Creative Commons Attribution–ShareAlike 2.5 License (http://creativecommons.org/licenses/by-sa/2.5/).

this episode

Mar 6, 2008 - Code coverage (also called test coverage) measures which lines of source code have been ... Check coverage results from your tests.

192KB Sizes 3 Downloads 326 Views

Recommend Documents

this episode
Mar. 6, 2008. Understanding Your Coverage Data ... Statement coverage does not measure the percentage of unique execution paths exercised. Limitations of statement ... recovery when kRecoverableError is returned. With tests that generate ...

SEO This Week Episode 17 2017 Strategy HTTPS Design Terms ...
Our Insights: We use Twitter primarily as a traffic generation tool, not. as a lead generation system, and yet this post has some very actionable. information that ...

Episode #21: So.....this is...... yeah!
Welcome to What Does It Matter? Podcast! Episode #21: So.....this is...... yeah! ... http://www.twitter.com/wdimpodcast · https://www.facebook.com/wdimpodcast.

episode
Aug 21, 2008 - def DrinkCoffee(): self.caffeinated = True. DelegateToIntern(work=Intern().MakeCoffee, callback=DrinkCoffee) self.assertFalse(self.caffeinated ...

episode
Aug 21, 2008 - More information, discussion, and archives: http://googletesting.blogspot.com. Copyright © 2007 Google, Inc. Licensed under a Creative ...

[Full Episode] Dance Moms Season 4, Episode 13 Online.pdf ...
[Full Episode] Dance Moms Season 4, Episode 13 Online.pdf. [Full Episode] Dance Moms Season 4, Episode 13 Online.pdf. Open. Extract. Open with. Sign In.

EpisodE 2: REVoLUTioN
The Declaration of Independence is read to jubilant crowds in New. York on July 9, 1776. America's thirteen colonies have taken on the might of the world's ...

Episode 38 - Annemarie Cross
Sep 30, 2016 - Annemarie Cross: You're listening to Women in Leadership podcast episode 38. Hi, I'm your host. Annemarie Cross branding communication strategist also known as the podcasting queen. Joining me on today's show is Stacey Copas, and she n

Episode 20 - Annemarie Cross
May 27, 2016 - won't, and what a wonderful problem to have and then in the early days ... in I personally sign it for them and then I give it to them and they are ...

Episode 16 - Annemarie Cross
Apr 29, 2016 - Joining me on today's show is Tracy Hall and Tracy is a mentor and trainer. She's ... people see the direct sales industry as an ethical business.

Episode 17 - Annemarie Cross
May 6, 2016 - Katy you've been really fortunate throughout your career. You've had ... Unequivocally, I think as I've grown in my career and I think this is really.

Episode 20 - Annemarie Cross
May 27, 2016 - would say go for it and don't underestimate the power of what it can do .... it's stopping you from capturing and communicating what makes you ...

Episode 38 - Annemarie Cross
Sep 30, 2016 - WomenInLeadershipPodcast.com |Connect with your Host onTwitter:@AnnemarieCoach. Email: [email protected] ... they're working in their own business and they would love to have their book. To get the time and get thoug

Episode 22 - Dr. Axe
Tony: You know, I had somewhat of a securities route to my land of fitness. .... we'll go out and buy a new phone, even though the last one we bought was only .... we...there are these companies out there, these fast food companies, these food ...

Episode 44 - Annemarie Cross
Nov 11, 2016 - You've set up and run your own awards and your conference. ..... want to bring that approach into how you do business and you're consistent with that. Alli: Yes. .... device. Anyway have a fantastic week. Thanks again Alli. Alli:.

Episode 19 - Annemarie Cross
May 19, 2016 - Email: [email protected]. So many women, men too but women in leadership that's what this show is all about, they struggle to communicate the value that they offer. So whether it is talking to a prospective client or

Episode 16 - Annemarie Cross
Apr 29, 2016 - She is committed to giving back to the industry that has provided her income and ..... culture and the name that you want in your business. So very, very .... Why I mention that is that as leaders we can set example. Our attitudes.

Episode 19 - Annemarie Cross
May 19, 2016 - was an ambulance. I turned around I said, “Mate, this is why I wanted to leave early. “ he laughed at me and he said, “Mom, if we were early, we ...

Episode 16 - Annemarie Cross
Apr 29, 2016 - Joining me on today's show is Tracy Hall and Tracy is a mentor and ... passionate about and that you really want to stand up for and bring this ...

Episode 17 - Annemarie Cross
May 6, 2016 - Web:www.WomenInLeadershipPodcast.com |Connect with your Host onTwitter:@AnnemarieCoach ... own and that certainly is not the case and certainly not the best way to go about it. I think in terms of my experience ...

Episode 17 - Annemarie Cross
May 6, 2016 - necessarily mean chaos. It means large complex solutions and global corporate. It ... today would like to get in contact. What's the best way?

Episode 44 - Annemarie Cross
Nov 11, 2016 - earth can I ever possibly stand out from what they're doing and offering? But ... You've set up and run your own awards and your conference.

Episode 38 - Annemarie Cross
30 Sep 2016 - Hi, I'm your host. Annemarie Cross branding communication strategist also known as the podcasting queen. Joining me on today's show is Stacey Copas, and she not let ... Instead, she has used her life experience and personal philosophies