Agile FAQs
  About   Slides   Home  

 
Managed Chaos
Naresh Jain’s Random Thoughts on Software Development and Adventure Sports
     
`
 
Discovering...
Industrial Logic

Microblog Feed
    Previous Feeds...
    Recent Thoughts

    Recent Comments
    Categories
    Archives
    March 2010
    M T W T F S S
    « Feb    
    1234567
    891011121314
    15161718192021
    22232425262728
    293031  
    RSS Feed
    Add to Technorati Favorites

    Refactoring Teaser IV Solution Summary Report

    Sunday, September 27th, 2009
    Topic Before After
    Project Size Production Code

    • Package =4
    • Classes =30
    • Methods = 90 (average 3/class)
    • LOC = 480 (average 5.33/method and 16/class)
    • Average Cyclomatic Complexity/Method = 1.89

    Test Code

    • Package =3
    • Classes = 19
    • Methods = 106
    • LOC = 1379
    Production Code

    • Package = 2
    • Classes =7
    • Methods = 24 (average 3.43/class)
    • LOC = 168 (average 6.42/method and 18.56/class)
    • Average Cyclomatic Complexity/Method = 1.83

    Test Code

    • Package = 1
    • Classes = 4
    • Methods = 53
    • LOC =243
    Code Coverage
    • Line Coverage: 88%
    • Block Coverage: 89%

    Code Coverage Before

    • Line Coverage: 95%
    • Block Coverage: 94%

    Code Coverage After

    Cyclomatic Complexity Cylcomatic Complexity Before Cylcomatic Complexity After
    Coding Convention Violation 85 0
    • Share/Bookmark

    Signs of a Healthy Codebase

    Tuesday, August 11th, 2009

    I’ve become a big fan of displaying metric using Treemaps. Julias Shaw’s Panpoticode is a great tool to produce useful design metic in the treemap format for your Java project.

    In the past, I’ve used these graphs to show Before and After snapshots of various projects after a small refactoring effort. In this blog I want to show you a healthy project’s codebase and highlight somethings that makes me feel comfortable about the codebase. (Actually there is not much to talk, a picture is worth a thousand words.)

    Following is the code coverage report from a project:

    papu_codecoverage

    Couple of quick observations:

    • Majority of the code has coverage over 75% (Our goal is not to have every single class with 100% code coverage. Code Coverage does not talk about Quality of your tests.)
    • There is a decent distribution of code across packages, classes and methods. (No large boxes standing out.)
    • You don’t see large black patches (ones you see are classes that were mocked out for testing).

    Lets look at the complexity graph:

    papu_cyclomatic_complexity
    • Except for a couple of methods, most of them have Cyclomatic Complexity under 5.
    • You don’t see large red or black boxes which are clear indicators of complex code.

    Panopticode combined with CheckStyle, FindBugs and JDepends can give you a lot more info to check the real pulse of your codebase.

    • Share/Bookmark

    Cobertura Gottachs

    Friday, October 3rd, 2008

    Today I spent a good 3 hours trouble shooting issues with code coverage on a legacy project. I’ve been using Cobertura for a good 3 years now. Hence I decided to use Cobertura to help a team working on a legacy project. What looked like a simple 10 mins job, ended up taking forever.

    To start off, the team did not have an automated build. So I quickly put an Ant script together. Last 2 days I had helped them write some acceptance tests using FitNesse. I set up the build file to run the FitNesse tests as part of the build. Once I had the testing in place, I wanted to see what kind of code coverage we had. So we started adding Cobertura Ant tasks to the build. This was a fairly trivial task. But surprisingly cobertura-report kept displaying N/A for Line and Branch coverage. Clearly there was something wrong.

    After spending a good amount of time, I realized that we need to compile the source code with debug=true option, else Cobertura does not generate any coverage numbers. What’s amazing is, it does not complain (in the normal mode) about this nor does cobertura’s documentation talks about this. When I ran the ant build in verbose mode, it showed the following warning

    [cobertura-instrument] WARN visitEnd, No line number information found for class

    That’s when it occurred to me that I need to compile my source code with debug=true option.

    Once I solved this problem I hit the next roadblock. Even thought I fixed the debug=true option issue, cobertura-report was still displaying N/A for Line and Branch coverage. I quickly wrote a dummy unit tests and that seemed to work. Cobertura report started showing some numbers. But I was not able to generate any coverage numbers from the main Java application (server) that I was trying to test.

    I knew there was some problem with the Shutdown hook not been executed correctly to flush the coverage numbers to the ser file. It turned out that if you have a server which is started as a daemon process in a forked JVM in the build, it needs to have a way to shutdown the server gracefully. So I ended up writing a shutdown command for the server which would basically do a System.exit(0). One need to explicitly call the shutdown script before calling the cobertura report target.

    Finally after 3 hrs, there was some ray of hope in my life when I saw a good 86% code coverage. This meant I could now go and refactor the code till I dropped dead.

    • Share/Bookmark
        Licensed under
    Creative Commons License
    Design by vikivix