Archives

Archives / 2008 / June
  • Unit Test Code Coverage - What Is A Good Number?

    Shawn writes that you should have 100% test code coverage, Jason agrees. Tokes, a co-worker and the person who pointed these posts out to me, disagrees.

    I also disagree.

    Background

    I'm a strong believer in unit testing. I have used unit testing in almost every project I have been involved in for a couple of years now and each time I find I get more and more value from using them.

    My experience with code coverage tools is more limited. I first started looking at NCover and code coverage after coming across an NCover article written its creator. The article used Json.NET, my own open source project, as the example! (if that doesn't prompt you to look at something nothing will [:D])

     I'll keep it short and sweet -- Family. Religion. Friendship. These are the three demons you must slay if you wish to succeed in business.

    Near the end of the development cycle of Json.NET 2.0 NCover was of huge help identifying which methods and sections of code didn't have any tests running over them. Without NCover many of the bugs I found from eventually unit testing that code would still be in Json.NET.

    Coverage Percentage

    While I think NCover is a great tool to identify what sections of code aren't being tested, the overall percentage mark that it gives is potentially dangerous.

    Every software project has limited resources and spending your time chasing that number is a poor use of it. 100% coverage certainly doesn't mean that your program is bug free. Code that works with one input will break with another.

    When it comes to unit testing I believe you are better off writing tests that focus on your use cases.

    Obviously checking that the results are right is important but there is also making sure that your code behaves as expected when passed boundary values, performing inverse operations and cross checking results elsewhere in the application. These are all important things to test when creating robust code but aren't necessary to achieve 100% coverage.

    A Good Number

    So what is a good number? If you have written tests the cover the possible uses of your application given the time available (NCover is useful for double checking that you are testing everything you want to) and have then have verified that the results are correct, whatever number your code coverage is at that moment is in my opinion a good number.

    Json.NET's was 85%

    The results are in: for Sideshow Bob, one hundred percent; and for Joe Quimby, one percent. And we remind you there is a one percent margin of error.

    kick it on DotNetKicks.com

  • What Is Coming In Json.NET 2.1

    Okay folks, show's over. Nothing to see here, show's... Oh my god! A horrible plane crash! Hey everybody, get a load of this flaming wreckage! Come on, crowd around, crowd around! I have just checked in two new features coming soon in Json.NET 2.1: Silverlight client support and improvements to the LINQ to JSON objects. If you are feeling cutting edge you can download the latest source code from CodePlex. Buyer beware: Code coverage of the changes is currently light.

    To compile a Silverlight build of Json.NET you will need the latest Silverlight 2.0 Beta 2 bits. There is also a unit test project in the solution for the Silverlight build. Read about how it works here (I really wish this was around when I was working on TextGlow).

    The LINQ to JSON changes are minor but useful. JObject now implements IDictionary and JArray now implements IList. For those that are new to Json.NET these common interfaces should make working with LINQ to JSON objects much more familiar.

    If you have any suggestions of what you would like to see in Json.NET 2.1 let me know.

  • I Don't Read Programming Books - What Am I Missing Out On?

    Not only am I not learning, I'm forgetting stuff I used to know. Of Jeff Atwood's list of 16 recommended books for developers I have read zero. Ditto this list of Top 20 Programming Books. Searching though Amazon recommended programming book lists also yielded no hits.

    When learning a new software development technology or idea I have always turned to the web. Blogs, articles, open source projects and so on, leaving the books I read largely to fiction.

    What am I missing out on? Are blogs and other online content enough or will reading The Pragmatic Programming (common to almost every list) make me a better software developer?