Thursday, February 25, 2010

Code coverage & cyclomatic complexity calculations coming to ColdFusion

We've heard it over and over again that ColdFusion 9 has made excellent headway in terms of providing engineers with great support to execute proper object orientation without all the bloat. Along with CF9 and awesome unit testing tools like MXUnit and Mockbox, unit testing is really becoming a mainstay for a lot of ColdFusion applications and I hope that it continues to stay that way. 


However one critical and often overlooked aspect of unit testing is code coverage and cyclomatic complexity calculation. Often times, developers feel that just because they've got a good amount of tests that its "good enough" without taking a step back and asking themselves questions like:

  • Are my unit tests covering every line of code?
  • Am I testing for every distinct path of execution inside a method?
  • Is my code written efficiently or is there room for improvement?
Perhaps you've asked yourself these questions but didn't know what the answers to it are. Well the answers lie in code coverage and cyclomatic complexity...

Code Coverage

Code coverage metrics show you the percentage of code that is covered and not covered by your unit tests. This is extremely beneficial to identifying the "holes" in your unit tests. Uncovered lines means no unit tests exist for those lines which is an indirect measurement of code and test quality. If you have not tested it, then it's at risk for error and should be addressed asap before rolling that beaut into production.

Cyclomatic Complexity

Also known as CCN, it answers the question of "is my code written efficiently?". To boil it down, take a method and imagine all the ways you as the developer can cause simple or complex conditionals. Meaning if's, switches, nested if's, inline method calls to other methods etc... 

The basic idea is that each of these "conditional" execution paths add to code complexity. In the programming world you always want to keep code complexity to a minimum because the more complex conditional code you have riddled throughout your code base, the less maintainable it is and extensibility becomes almost impossible. Your software becomes risky as more complex paths are added resulting in unhappy customers and stressed out engineers - and I think you'd agree with me that stress sucks and in a volatile software, release days are nail biters... 

So the idea is that you run CCN metrics on your classes and it will spit out a number for you. The standard is that the number should be under 10 and anything over that should be flagged, reviewed and more often that not re-written.

Code Coverage and CCN coming to ColdFusion


In languages like Java and C#, there are tools that provide this level of support but not for ColdFusion. That is until now!


Written with Java and ColdFusion, cfcommon's Chimera project will provide you with that critical line of defense to help engineers identify parts of their code that need unit tests and/or need to be re-factored because of too much complexity.


Attached is a preliminary screenshot of Chimera playing nicely with MXUnit tests.


Chimera ColdFusion Code Coverage Analysis


Although this image shows ColdFusion code writted in tags, we will also be providing script support as well ;)


Please stay tuned as we will be releasing Chimera BETA very soon and you can check out cfCommons in the meantime!


PEACE.


Mick

9 comments:

Marc Esher said...

This is great news, Micky!

LED Signs said...

This is because the more intricate conditional code you having challenged throughout your code base, the less maintainable it turns into and extensibility becomes more or less unfeasible.

Anonymous said...

Is the project dead?

Micky Dionisio said...

It is not. The website will be back up shortly.

Dave said...

I'd love to see the Chimera beta! The CF world definitely needs a code coverage tool!

Colin Jones said...

This would be fantastic - we'd love to add Chimera to our growing list of TDD tools, mxunit, ant, hudson. Any chance of seeing the alpha?

Shankara said...

I kind of disagree to the statement that CCN improves efficiency. CCN may improve the maintainability by reducing complexity of the code, but that alone does not make it efficient. Efficiency relies on the algorithm/solution used to write the piece of code. By reducing complexity, it does not certify if the solution is efficient or performant.

Christine said...

So, Is this dead? I would love to see the Chimera beta for CF9.

Code Fusion, LLC (Kevin Penny) said...

Any movement here? Can the alpha be released to play with / help contribute to? There are reasons why enterprises move away from ColdFusion - they need answers to 'what does your code coverage look like?'

Post the alpha and let the community help!