password
username
Sponsored by CakeMail, an email marketing software.
Newsletter preview

Tuesday, Nov 4, 2008

The Fastest Way to Improve Your Reporting

Eclipse BIRT, which has been downloaded over 5 million times, is one of the most popular open source reporting technologies. The new BIRT Report Factory makes migrating to modern, web-based reporting simpler than ever. It’s a pay-as-you go service that provides the fastest and most cost-effective way to develop and deliver BIRT reports..

Get the details on the BIRT Report Factory here.

Perspective

How to Use Open Source SOA Safely in the Enterprise



Visit the DZone Tech Library


A Developer's Perspective
Next section
Kevin Pang is an ASP.NET developer, ALT.NET supporter, and published writer based out of southern California. Kevin's blog covers not only the technical aspects of software development, but the personal aspects as well.

Is Code Coverage Really All That Useful?
By Kevin Pang

Test driven development proponents often tend to push code coverage as a useful metric for gauging how well tested an application is.  100% code coverage has long been the ultimate goal of testing fanatics.  But is code coverage really all that useful?  If I told you that my application has 100% code coverage, should that mean anything to you?

What does code coverage tell us?
Code coverage tells us which lines in our application are executed by our unit tests.  For example, the code below has 50% code coverage if the unit tests only call Foo with condition = true:

string Foo(bool condition)
{
    if (condition)
        return "true";
    else
        return "false";
}

What does code coverage not tell us?
Code coverage does not tell us what code is working and what code is not.  Again, code coverage only tells us what was executed by our unit tests, not what executed correctly.  This is an important distinction to make.  Just because a line of code is executed by a unit test, does not necessarily mean that that line of code is working as intended. 

For example, the following code could have 100% code coverage and pass all unit tests if it is never called with b = 0.  However, once this code is introduced into the wild it could very well crash with a div by zero exception:

double Foo(double a, double b)
{
    return a / b;
}

So what is code coverage good for then?

To borrow an analogy from Scott Hanselman's interview with Quetzal Bradley, imagine you are a civil engineer responsible for testing a newly constructed series of roads.  To test the roads, your first thought might be to drive over them in your car, making sure that there are no potholes, missing bridges, etc.  After driving over all of the roads a few times, you might conclude that they have been tested and are ready for public use.  But once you open the roads to the public, you discover that the bridge overhangs are too low for big rigs, the turns are too sharp for sports cars, and that certain areas of the roads flood when it rains. 

In the above scenario, you had the equivalent of 100% code coverage since you had driven over all the roads, but you only superficially tested their behavior.  Specifically, you didn't test the roads in different vehicles and under different weather conditions.  So although you went through each possible execution path, you failed to accomodate for different states while doing so.

In light of this, the only solid conclusion you can draw from code coverage seems to be what lines of your code have definitely not been tested.  The lines that have been tested are still up for grabs it seems unless you are willing to go through each and every possible state the application can be in when executing them.  This makes code coverage far less useful as a metric as it only tells you what still needs testing but offers you no help in determining when you are done testing.

What *is* a good metric then?
Unfortunately, there doesn't seem to be a good metric for determining whether a line of code has been thoroughly tested or when a developer is done testing.  Perhaps this is a good thing as it keeps us from falling into a false sense of complacency.  It simply isn't feasible in even a moderately complex application to test each and every line of code under every possible circumstance.  The best case scenario seems to be to test the most common scenarios and reasonable edge cases, then add additional tests as functionality inevitably breaks on those scenarios that you didn't account for.  It's an admitedly clumsy system, but it's a realistic one compared to depending on 100% code coverage to weed out all possible bugs.  That's not to say that there isn't use in achieving 100% code coverage.  Executing the code in one particular state still has value, just not as much as developers seem to give it.

Until next time,
Kevin Pang

To read more of Kevin's work, visit his blog.

 

Free Cheat Sheet: JUnit and EasyMock

JUnit and EasyMock are the predominant choices for testing tools in the Java space. This reference card will guide you through the creation of unit tests with JUnit and EasyMock. It contains detailed definitions for unit testing and mock objects as well as a description of the lifecycle of each. The APIs for both JUnit and EasyMock are covered thoroughly so you can utilize these tools to their fullest extent.

Download this free cheat sheet now!
DZ Top Links

DZone Top Links
Next section
Back to top
most clicked this week from dzone.com

dzone

Most-clicked links this week


 
Popular at JL

Popular at Javalobby
Next section
Back to top
A recap of some of the most popular and active Javalobby.org discussions this week.

My Top List of Java Tools

Lack of imagination is one of our worst sins as software developers. We do the same things over and over again, but we rarely modify our ways: me at least....

3 replies - 6060 views - 10/30/08 by Ignacio Coloma in Articles

Seven Forms of Business Process Management With JBoss jBPM

This article will explain Business Process Management (BPM) in terms of 7 distinct use cases for JBoss jBPM. By giving more insight in those use cases, you'll...

0 replies - 5695 views - 10/21/08 by Tom Baeyens in Articles

What is Wrong with JDK Logger?

I used to use log4j because it was most popular, but recently decided to try JDK logger in my current project. I like that it is built into the JDK so there...

29 replies - 3822 views - 10/29/08 by Ryan de Laplante in Articles

Possibly The Best Way To Be A Great Programmer: Be Brain-Healthy!!

I was watching a television show on PBS (viewer-sponsored educational public broadcasting) about brain health. The speaker was Daniel G. Amen, author of the...

4 replies - 3728 views - 10/28/08 by Jon Davis in News

When Good Annotations Go Bad

At one time not too long ago, I wasn't a big fan of annotations. But then I let my guard down and even started liking them. But now I'm starting to wonder if...

19 replies - 3501 views - 10/22/08 by Craig Walls in Articles

Want Closures in Java 7? Vote!

Although Sun Bug Database is somewhat unpopular it is at least one way to influence the future of Java. I have read many articles on the web where developers...

68 replies - 3449 views - 10/23/08 by Tim in News

Dependency Injection Myth: Reference Passing

After reading the article on Singletons (the design anti-pattern) and how they are really global variables and dependency injection suggestion to simply pass...

0 replies - 3016 views - 10/22/08 by mhevery in Articles

White Papers & Announcements

Product Announcements
Next section
Back to top
Product and service announcements for Java developers.

NetBeans IDE 6.5 Release Candidate 2 Available

The second Release Candidate of NetBeans IDE 6.5 is now available. The release is also multilingual—downloads are available in Japanese, Simplified Chinese,...

0 replies - 1642 views - 10/30/08 by Rob Demmer in Announcements

Galileo RIA Toolkit Release 1.0 Beta

Galileo RIA Toolkit Release 1.0 Beta is now available @ www.galileo-riaf.comWhat is Galileo?Galileo was created for software engineers looking for a Rich...

8 replies - 1258 views - 10/29/08 by mwarble in Announcements

New Interactive Help Application for Java Developers

IDRsolutions are pleased to announce, their new PDFhelp application, offering developers a much easier and slicker way to provide online help in Java...

2 replies - 1097 views - 10/28/08 by mark stephens in Announcements

JDO 2.2

Apache JDO release latest revision of the Java Data Objects specification, API and TCK JDO 2.2 has been released by Apache JDO. The API jar and most recent...

0 replies - 845 views - 11/02/08 by Andy Jefferson in Announcements

JUnit and EasyMock Refcard Available - Download Now

JUnit is a free, elegant and easy Java unit test framework that developers in the know use to increase the stability of their software. Often used together...

0 replies - 750 views - 11/02/08 by Jill Tomich in Announcements

JPPF 1.6: Java-Based Open Source Grid Computing Platform

In this version:

1 replies - 743 views - 10/30/08 by Laurent Cohen in Announcements

JNIWrapper Now on Mac OS X 64-bit

JNIWrapper - Use Native Code from Java without JNI. Now on Mac, too. JNIWrapper provides simplified access to native code from Java applications without...

9 replies - 676 views - 10/29/08 by Igor Shvydkoy in Announcements

Java Print Dialog Framework Version 2.0

Soft Frame Works has recently released the Java Print Dialog Framework version 2.0.

0 replies - 620 views - 10/29/08 by Henry Lander in Announcements

Export Documents to DOCX, DOCM, DOTX & DOTM Formats in Java Apps

What’s new in this release?The new version of Aspose.Words for Java - 2.5.0.0 allows you to save documents in DOCX, DOCM, DOTX, DOTM formats. This version...

3 replies - 611 views - 10/29/08 by Usman in Announcements

Code Consultant IntelliJ Plugin Initial Release

Have you ever noticed that simple act of describing a problem you can't get past to a co-worker will help you solve the problem, even if they don't say a...

0 replies - 578 views - 10/29/08 by Nathan Voxland in Announcements

Ebean ORM v0.9.8

Ebean ORM adds support for Enhancement via javaagent, Eclipse IDE Plugin and ANT task to existing Subclass Generation approach. The User Guide includes a...

1 replies - 561 views - 11/01/08 by Robin Bygrave in Announcements

JDebugTool 4.1.3: Graphical Java Debugger

JDebugTool from debugtools.com LLC is a: Standalone graphical Java debugger.Built on top of the standard JPDA (Java Platform Debugger Architecture).Is itself...

0 replies - 516 views - 11/03/08 by debug tools in Announcements

Introducing Milton: An Open Source Webdav API for Servers

Milton is an open source java library for implementing desktop integration in your web apps with WEBDAV.For those not familiar with WEBDAV, its like FTP but...

0 replies - 508 views - 10/29/08 by brad_the_mc in Announcements

ZK Timeplot (timeplotz) 1.0_2 released

Timeplot is a DHTML-based AJAXy widget for plotting time series and overlay time-based events over them. You can populate Timeplot with data by pointing it to...

0 replies - 439 views - 10/28/08 by robbiecheng in Announcements

Hazelcast 1.4: Distributed Events

Hazelcast is a free distributed/partitioned queue, map, set, list, lock and executorservice implementation for Java. 1.4 release focuses on distributed events...

0 replies - 363 views - 11/03/08 by Talip Ozturk in Announcements

Your Account

Your Account
Next section
Back to top
Manage your account info for this and other Javalobby publications.

Manage your Javalobby membership details

Click on the following links to:

Contact Info
Next section
Back to top
Here's how to reach us, we love to hear from you.

Email us
Send news items to editor@javalobby.org
Send questions, complaints, or suggestions to feedback@javalobby.org
Send advertising inquiries to advertise@javalobby.org
 
  Call us
  Our number is (919) 678-0300. We'd love to hear from you!
Legal
Back to top
The fine print we'd rather avoid completely.
  Feel free to redistribute this newsletter in part or in full to your friends.
 
Javalobby News is a service mark of DZone, Inc.
Copyright © 2001-2008 DZone, Inc.

Thank you for your continued support of Javalobby and DZone. Click here if you prefer not to receive the Javalobby weekly newsletters.
DZone, Inc. - 1251 NW Maynard Rd. - Ste. 300, Cary, NC 27513 - (919) 678-0300