Oisín Hurley's Weblog

old dog, new tricks

Is your code C.R.A.P.?

leave a comment »

Just got a link this morning to the C.R.A.P. metric and the crap4j Eclipse plugin. This humourously-named approach mixes up cyclomatic complexity and code coverage to give a number that is your code’s CRAP index. Generally speaking, you can lower your CRAP index either by adding automated tests or by refactoring to reduce complexity, or both.

Apparently crap4j can also estimate your CRAP Load (we’ve beaten this one to death – ed.), in which it gives an indication of how many tests you will need to write to reduce the CRAP index to less than an arbitrary bar of 30.

Update: tried it out, and it seems interesting – I can understand the concepts immediately and it has an amusing toilet paper icon on the menu. Here’s a screenshot of the CRAP Report that it produces.

crappy.png

In the case of this anonymous component, you can see that the crapometer weighs in at 14.91% – an artitrary figure that tells me that a little over one in seven of the methods in the component are, well, crappy.

crapload.png

The CRAP Load figure above hints that maybe about 14 tests would do the trick in reducing the CRAP figure of a complex method with 0% coverage.

Advertisements

Written by oisinhurley

October 9, 2007 at 8:19 am

Posted in eclipse, Testing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: