| «« I Hit the Pin? | Coverage Isn't a Silver Bullet »» |
|
About
I'm Ryan Lowe, a Software Engineering graduate living in Ottawa, Canada. I like agile software development and Ruby on Rails.
I write this blog in Canadian English and don't use a spell checker. Typos happen.
Projects
» Full-time Ruby on Rails freelancer
» Full-time with Rails since May 2005 » Former committer for RadRails (now Aptana) » I also have a few Rails side-projects in development: 1. wheretogoinTO.com Toronto nightlife 2. Hey Heads Up! TODO list and sharing 3. Layered Genealogy family history research 4. foos for foosball scoring 5. fanconcert for music fans (on hold) Hiring Rails developers? I can telecommute by the hour from Ottawa, Canada »» Email: rails AT ryanlowe DOT ca
BulletBlog
Now hosted on Hey! Heads Up -- check it out!
Syndication
Pings
Recent
Derek Lowe's (Ryan's older brother) words at Ryan's funeral
blog@ryanlowe.ca no more Forging Email Headers: Good, Bad or Ugly? Sarcastic Dictionary (Part 1 of Many) Tags Hierarchies Twisting Rails is Risky Business Risky Business? My Take on Early Alphas Whoa, it's August 2007 Closing Comments A Postscript to "Growth at the grassroots" »» All Blog Posts
Linkage
del.icio.us/ryanlowe
technorati/ryanlowe.ca/blog Aurora Roy Jim Andrew Trasker Travis Kibbee Karen Dr. Unk Ayana Van Bloggers Joel Spolsky Robert Scoble Tim Bray Dave Winer Raymond Chen James Robertson Ruby/Rails Bloggers rubyonrails.org weblog David Heinemeier Hansson Dave Thomas James Duncan Davidson Mike Clark Jamis Buck Signal vs. Noise Tobias Luetke Amy Hoy: (24)slash7 Jeremy Voorhis Eclipse Bloggers Planet Eclipse EclipseZone Luis de la Rosa Eclipse Foundation Kim Horne Billy Biggs Ian Skerrett Mike Milinkovich Bjorn Freeman-Benson Denis Roy
Archives
|
Code Coverage
Think that just because you use JUnit and test-driven development that your code is well tested? Actually, probably not. One of the key tenets of XP is that no line should be in your code that isn't necessary. If you take a line out of your code it should break at least one test. If it doesn't, delete it or write more tests!
Coverage tools work by marking the compiled code so that lines can be counted by the number of times they are executed. Then you can run your test suite over this modified version of your compiled code to see where the test suite hits and where it misses (see picture). You can even see which specific lines of code you forgot to cover. Then you have a choice: write the tests that cover those lines or decide they are useless and remove them. Some lines are impossible to get to -- a silly example would be: if (x < 10) { You would never get to the println(). When you refactor complicated code over and over it's hard to tell when you've cut a chunk of code off and made it impossible to execute. That cruft can be removed to simplify what's left. So your tests test your code and coverage tools examine your tests. It's a great way to keep on top of the quality of your tests and your code. So get a code coverage tool! If you have the means I highly recommend picking one up ... it is so choice. Posted at June 23, 2003 at 01:04 AM ESTLast updated June 23, 2003 at 01:04 AM EST Comments
My favourite part is how you can look at the source and it tells you EXACTLY how many times that line was hit. Much better than a simple percentage given. I don't know about the colours though... I would rather get something in teal and tope. hahahaha.... ;-) » Posted by: Jim at June 23, 2003 04:04 PMCan you use these with VB? :-P lol » Posted by: roy at June 24, 2003 02:09 AMHey, Ryan-- Just googled across your blog. You seem to be familiar with some of the intimacies of JUNIT / JCOVERAGE / ECLIPSE / ANT. I'm a loyal JUNIT user for Eclipse, and want to start checking how well these JUnit tests hit my code. So that would be, presumably, something JCoverage can do. Which means, in turn, that I need to set up JUnit as a compilation target, and I'm having a lot of trouble with that. Silly tag doesn't seem to want to work. Can I ask if you've pulled it off? » Posted by: Dan at July 2, 2003 04:04 AMI am sort of familiar -- I got it to work in two cases. :) I am going to write a post on how to do this soon, since it's not described well in the Ant manual. I had to piece it together myself from various places. The jcoverage documentation is also fairly brief and I'd like to do a post on that as well. I'll email you when I get it done so you know ... » Posted by: Ryan at July 2, 2003 02:14 PM |