Tuesday, May 09, 2006

Code Coverage Tools

A recent problem arose at work where our code coverage tool, Cobertura ceased to work for a particular application. Well actually, "ceased" is the wrong word. It didn't work from the get-go. We had however, been using Cobertura succesfully with other apps. We discovered that the problem was due this particular app already having it's bytecode instrumented by a tool called Versant Enhancer. So we had both Versant Enhancer and Cobertura trying to instrument the same bytecode with the result that either the code didn't work, or we got no coverage figures, or both.
So what to do? We like Cobertura but we can't use it on this app unless Cobertura or Versant engages in a major re-write for our sake. Which isn't gonna happen.
Another coverage tool is Emma, but that too instruments the bytecode, ruling it out.
We also have access to PureCoverage* but found it to be too unstable in our Java development environment (haven't tried it with C) to be useful.
Finally a viable alternative to Cobertura emerged.
Clover is a commercial coverage tool that instruments the sourcecode, thereby preventing our problem with Versant. We're about to start trials to make sure this is the case, and I'll post the results in a few weeks.
To sum up:
ByteCode Instrumentation Coverage Tools:
Cobertura
EMMA

SourceCode Instrumentation Tools:
Clover

You can check Cobertura out here:
http://cobertura.sourceforge.net/
You can check EMMA out here:
http://emma.sourceforge.net/
You can check Clover out here:
http://www.cenqua.com/clover/

*PureCoverage is available only as part of Rational PurifyPlus. I've included a link to that product in the sidebar.

Findbugs

While we use PMD at work for our static code analysis, much has been made of late of FindBugs, a similar tool to PMD developed by the University of Maryland. Many reviews of both PMD and FindBugs suggest using them to complement one another.
Find out more about this tool here:
http://findbugs.sourceforge.net/

Using Ant behind a proxy server

A problem recently cropped up with my build that was caused by the xerces xml parser trying to validate an xml using the dtd reference in the file. The problem was that the dtd was stored on the web. The web in turn, was only accesible through our corporate http-proxy server, which neither Ant nor the JVM knew anything about.
After some searching I discovered there's an Ant task called "setproxy" that allows you to inform Ant of your proxy setup, so anything else run in the same JVM has access to the web.
You can find out how to use the "setproxy" task here:
http://ant.apache.org/manual/OptionalTasks/setproxy.html

Monday, May 08, 2006

Groovy: A new language for the JVM













I could try and explain what Groovy is myself, but it's best to quote from this website:

"Groovy. No, this isn't a review of the latest Austin Powers movie. Instead, it is about an evolving new language for the Java 2 platform. Yes, new language. The Java platform is that, a platform, not just a programming language. What Sun Microsystems provides is a complete platform: a programming language, a core set of libraries, and a runtime environment, where the last bit is also known as the Java virtual machine
1 or JVM. The instruction set of the JVM is a set of operational codes or opcodes as defined by the Java Virtual Machine Specification. The virtual machine doesn't care what programming language those opcodes started as, as long as what the JVM sees is the appropriate opcodes. And, that's where Groovy comes in. Through JSR 241, the Java Community Process is helping to standardize a new language for the Java platform. According to Richard Monson-Haefel, a Sr. Analyst of Burton Group and former specification leader, "The Java programming language is excellent for large complex systems, but it can be overkill when it comes to small jobs." And, that's what Groovy offers, a scripting language that runs natively on the JVM and works with Java objects, APIs, and tools.

According to James Strachan, expert group lead and Groovy co-founder (with Bob McWhirter), Groovy started with a desire for "an alternative to javac, which had the power and expressiveness of Ruby/Python but generated regular Java classes (at runtime or build time) and that worked directly with Java classes without some other layer. So I wanted a Groovy object to descend from java.lang.Object, with collections being java.util.Collection, lists being java.util.List, support for Java arrays, Java beans, and for all the APIs in the system to be based on Java 2 Platform, Standard Edition (J2SE) and Java 2 Platform, Enterprise Edition (J2EE)."

So there you have it. But why include information on Groovy in a Java test-tool blog? Well, most of the compilation/testing tools now offer support for Groovy. Ant and Cobertura are just 2 of the tools offering support.
Again, I haven't had time to look into detail, but said I'd put the information out there.
You can grab Groovy here:
http://groovy.codehaus.org/

Continuous Integration: Update

One of the most well known articles on the "continuous integration" aspect of Extreme Programming has recently been revised and brought up to date.
Click here:
http://www.martinfowler.com/articles/continuousIntegration.html

Thursday, May 04, 2006

JUnit for beginners

If you're beginning to write JUnit tests, but haven't fully got your head around the whole unit-testing "thing", then a visit to the following site will probably prove useful:
http://www.clarkware.com/articles/JUnitPrimer.html
It's pretty basic, but should get you up and running.

CruiseControl & Useful Information

I'm currently evaluating (part-time) a number of different options for build automation. Maven+Continuum is a nice neat package, but (from initial inspection), not as flexible as Ant+Cruisecontrol+Ivy.
As I haven't posted much in the way of information on Cruisecontrol, I thought I would at least offer the following tip.
  • DON'T WASTE TIME LOOKING FOR USEFUL INFORMATION AT THE CRUISECONTROL WEBSITE.
There isn't a lot. If you want the lowdown on everything to do with CruiseControl head to:
http://confluence.public.thoughtworks.org/display/CC/Home

Its a wiki, fully endorsed by the developers of CruiseControl, that expands upon everything available at the official CruiseControl home, and adds a whole lot more. It should be everyone's first stop for all things CruiseControl.
If you feel like punishing yourself of course, head over to:
http://cruisecontrol.sourceforge.net/
and look for documentation....;-D

Ant in Anger: Using Apache Ant in a Production Development System

The following article "Ant in Anger" is an excellent guide to using Ant effectively in a production environment. As well as detailing best practices, it also lets the reader know what some of Ant's shortcomings are and how to work around them. It's included as part of every Ant distribution, but can be hard to find. You can find the article here:
http://ant.apache.org/ant_in_anger.html

And yes, I know it's more than a year old, but it has been updated since the last major release of Ant (1.6 at the time of this post. I consider 1.6.1-5 minor releases.), and the information contained within is still perfectly relevant at the time of this post.

Wednesday, May 03, 2006

Useful Maven Information Sites

Further to my last post regarding "Better Builds with Maven", I thought both of the sites below would also prove useful links with regard to Maven operation.

http://www.mavenblogs.org/
mavenblogs is a series of blogs written by Maven experts including the developers themselves, and has plenty of useful tips and tricks.

http://www.mavenbook.org/
mavenbook.org is a site set up to tie in with "Maven: A Developers Notebook" book. The site contains the source code for the examples in the book, but also offers plenty of non-book related material on Maven.

Of course don't forget to check http://maven.apache.org/ for updates on the tool itself.

Tuesday, May 02, 2006

"Better Builds With Maven" - A Free Guide to Maven 2.0

I've been playing around with Maven 2.0.4 for the last few days, having been impressed by what I'd heard about it. It's certainly powerful, and exceptionally lean, as is, unfortunately, the documentation.
However the main team working behind the scenese at Maven have just finished a full-blown book on it, and they're giving it away FOR FREE.
I've been using it for a day now, and it's pretty helpful, to say the least.
You can grab the book here:
http://www.mergere.com/m2book_download.jsp
Just follow the instructions and you'll be sent a link in your mail to download the pdf.