Thursday, May 23, 2013

Continuous Integration and Code Quality Tools - Part 2

Before I start off - CI actually means building the artifacts and testing them as well. You can run unit tests, integration and smoke tests as part of your Jenkins job.CI can be best suited to a Agile model where a daily/weekly build is necessary. CI is also useful for very huge projects in continuous development but I would not really recommend it for small projects which is for a one time release.

 So once we had the CI (Jenkins) setup and performing all our required builds, it was time for us to investigate into quality check tools. The first thing which we looked into was Unit testing - JUnit and TestNG. Junit is the widely used testing tool in Java and has been evolving all these years. TestNG on the other hand is a very strong flexible multipurpose testing framework. Wiki quotes it as "It uses Annotations since first version and is a framework more powerful and easy to use than the most used testing tool in Java: JUnit". TestNG even has a migration plugin with eclipse to migrate from Junit ;)

The next tool which we had our eyes on was something which could measure the code and branch coverage. JaCoCo, Clover and Corbetura were the competitors. Clover requires to instrument the source code,  Corbetura instruments the code offline where as JaCoCo allows to instrument the bytecode while running the code. In addition, JaCoCo is the only coverage tool which works completely with Java7. The next question for us was to determine the percentage which we want as standard. Industry standard by word of mouth is to have 50% code coverage because there would be only 50% of code which has some logic in them - the rest being DTOs..etc

The other question which we had, was to find a tool which makes sure that the Java Coding Standards are met. We looked at PMD and Checkstyle. Checkstyle checks the style of coding alone where as PMD on the other hand will point out questionable coding standards which is a bit more relevant. Researching on those tools, we also came upon Findbugs which is much more relevant and useful. This checks not just the style but also bad coding practices and unsafe code.

We did setup all these tool plugins and Jenkins and had quite some good success with it. That is when we stumbled upon Sonar. This tool did blow up our minds - it is a mix of all these tools mentioned above and more. In addition to these we could more plugins to it. Integration to Jenkins server was as simple as running an installation package. Sonar also provided a war file which can be deployed onto a web server. However, it performs better when connected to a actual RDBS rather than the embedded one. The tool runs all the different tools and generates a web dashboard which is quite intuitive. Sonar also provides a plugin for eclipse based platforms which is an additional advantage. The rules can be configured/customized in Sonar to suit needs of each of the project or the organization. Sonar does more than just running these tools for you, it can give you changes in improvements to the code after the change and costs for fixing some changes. Sonar Jenkins combination is a killer :)

No comments:

Post a Comment