Home > java > CodePro overview

CodePro overview

Google recently donated a code profiling product to eclipse. A related code analytics product named CodePro is worth a look. It integrates with eclipse nicely. Lets take it for a test drive

Code Audit:

This tool allows you to check for obvious mistakes in your code. Think findbugs. You can add / edit rule sets and then run a code audit. At the end of the auditing process, the results display shortcomings in the code. If you already work with findbugs, there is nothing new to see here.

Code review:

Testing tools:

Ever spent time writing tons of junit code ? CodePro can help cut that short by writing codegen that will automatically test paths in your code. Take this class for example

Hello world

package com.test;
 
public class HelloWorld
{
 
    public static void main(String... args)
    {
        new HelloWorld().go(11);
    }
 
    public void go(int i)
    {
        System.out.println("Hello world");
        if(i==10)
        {
            throw new RuntimeException();
        }
        System.out.println(i);
    }
}
The method go() has 2 flows. If i is 10, an exception is thrown. For any other value, everything is fine. To generate automated test cases, right click on the java file to be tested and click ‘CodePro -> Generate Test cases’. This automatically creates a new test project and a test java file. A junit test editor details the test cases
Junit test editor:
Notice that the cases i=10 and i=<Any number goes here> are covered. That is great. You can also edit the test cases in the window shown above. Changing the values in the editor changes the codegen appropriately

Codegened test cases:

    @Test
    public void testGo_1()
        throws Exception
    {
        HelloWorld fixture = new HelloWorld();
        int i = 1;
 
        fixture.go(i);
 
        // add additional test code here
    }
 
    @Test(expected = java.lang.RuntimeException.class)
    public void testGo_2()
        throws Exception
    {
        HelloWorld fixture = new HelloWorld();
        int i = 10;
 
        fixture.go(i);
 
        // add additional test code here
    }

Dependency Analysis:

This tool helps you untangle your dependencies. Dependencies are calculated at different levels. Project level dependencies on libraries; Package dependencies; Class dependencies etc. Here is an example of the same.
Dependency:

There are commercial eclipse plugins that do the same job. With CodePro this comes as one of features that can be used.

Code coverage:

Not much to say here. Code coverage is built on EMMA. You get everything that EMMA can provide, plus – Report generation; Historic view of coverage; Frequency with which code is executed; etc.

Metrics:

This gets pretty interesting. There are several factors involved in writing readable code that are seldom measured. Number of lines of code per method is one of them. If you have ever had the misfortune of analyzing a method with 1200 lines of code (yes it happened to me :( ), you would love to have this metrics tool. It helps catch violations like this quickly. The metrics that I found most useful were
Average number of…

  • lines per method
  • fields per type
  • Comment ratio
  • Methods per type

Wasteful code:



CodePro allows you to find duplicate code and dead code that will never be used. Dead code analysis is a little tricky and didnt quite work the way I expected it would. As for similar code, the tool does a good job and indicates which lines are similar to each other in the code base.
Duplicate code:
Give CodePro a try today. Consult the detailed documentation for more information





Categories: java Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.