Patrick Smacchia [MVP C#]

Sponsors

The Lounge

Wicked Cool Jobs

News

  • NDepend v3 is fully integrated in Visual Studio, and is now available for download! Software dependencies visualization, 82 .NET software metrics, continuous rule validations, assembly version diff, declarative code queries and more ! http://ndepend.com

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Are you sure added and refactored code is covered by tests?

I would like to make a point here on the fact that NDepend can answer what is maybe the most important question for an agile programmer:

Does added and refactored code is covered by tests?

There are 4 CQL default rules to address this need:

// <Name>Method where code was changed partially covered by tests</Name>
WARN IF Count > 0 IN SELECT METHODS WHERE 
  
PercentageCoverage < 100 AND PercentageCoverage > 0 AND
  
CodeWasChanged 
  
ORDER BY PercentageCoverage DESC , NbLinesOfCodeCovered , NbLinesOfCodeNotCovered 
 

// <Name>Method added partially covered by tests</Name>
WARN IF Count > 0 IN SELECT METHODS WHERE 
  
PercentageCoverage < 100 AND PercentageCoverage > 0 AND
  
WasAdded  
  
ORDER BY PercentageCoverage DESC , NbLinesOfCodeCovered , NbLinesOfCodeNotCovered 

// <Name>Method where code was changed not covered at all</Name>
WARN IF Count > 0 IN SELECT METHODS WHERE 
PercentageCoverage == 0 AND CodeWasChanged ORDER BY NbLinesOfCode DESC 


// <Name>Method added not covered at all</Name>
WARN IF Count > 0 IN SELECT METHODS WHERE 
PercentageCoverage == 0 AND WasAdded ORDER BY NbLinesOfCode DESC 


Of course, these rules can be refactored at whim, for example, to have just one rule that tells about all added or refactored method that are not covered by tests:

// <Name>Method added or refactored not fully covered by tests</Name>
WARN IF Count > 0 IN SELECT METHODS WHERE 
  
PercentageCoverage < 100 AND
  
(CodeWasChanged OR WasAdded)
  
ORDER BY PercentageCoverage DESC , NbLinesOfCodeCovered , NbLinesOfCodeNotCovered 

 

I wanted to make this point because I figured out that my friend Jason Gorman, which is certainly an advanced NDepend user, wasn't sure about this possibility (Identifying High Risk .NET Code With NDepend).

 

Why knowing if added or refactored code is covered is so important? Because if you can answer yes each time you are about to release a new version you'll end up after N iterations (N not too large) with a code well tested. As a consequence the number of bug will decrease, iterations after iterations, and a lot of time spent doing manual testing will be saved.

Is it pure theory? I can't answer, my common sense say yes it works, however I am not a theorist but a programmer. But I can attest that since we applied this methodology on the development of NDepend, the number of bug reported has decreased dramatically and our productivity increased significantly.

 

Concretely, these CQL rules sits on 2 features of NDepend that are:

Build comparison: the ability to compare 2 builds and to ask for which part of the code have been added/refactored/removed.

 

Test coverage data import from NCover™ or VSTS™ the possibility to ask for code fully, partially or not covered by tests.

And as all NDepend features, this possibility to know about refactored/non-tested code can be harnessed from the VisualNDepend UI but also from the CI build process by customizing NDepend project properties, as shown below:


 

 


Posted Thu, Jul 10 2008 11:36 AM by Patrick Smacchia

[Advertisement]

Comments

Dew Drop - July 10, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - July 10, 2008 | Alvin Ashcraft's Morning Dew
on Thu, Jul 10 2008 8:09 AM

Pingback from  Dew Drop - July 10, 2008 | Alvin Ashcraft's Morning Dew

Arjan`s World » LINKBLOG for July 11, 2008 wrote Arjan`s World &raquo; LINKBLOG for July 11, 2008
on Fri, Jul 11 2008 3:43 PM

Pingback from  Arjan`s World    &raquo; LINKBLOG for July 11, 2008

Useful Links #9 | GrantPalin.com wrote Useful Links #9 | GrantPalin.com
on Sun, Jul 13 2008 6:42 PM

Pingback from  Useful Links #9 | GrantPalin.com

Patrick Smacchia [MVP C#] wrote Ship It Often vs. TDD
on Sun, Dec 21 2008 11:49 AM

Ayende recently answered the question what the bare minimum aspects of Agile project would be? His opinion

Community Blogs wrote Ship It Often vs. TDD
on Sun, Dec 21 2008 12:33 PM

Ayende recently answered the question what the bare minimum aspects of Agile project would be? His opinion

Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas wrote Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas
on Mon, Dec 22 2008 6:04 AM

Pingback from  Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas

Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas wrote Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas
on Tue, Dec 23 2008 1:03 PM

Pingback from  Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas

Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas wrote Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas
on Wed, Dec 24 2008 10:01 AM

Pingback from  Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas

Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas wrote Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas
on Thu, Dec 25 2008 6:21 AM

Pingback from  Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas

Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas wrote Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas
on Tue, Dec 30 2008 6:03 AM

Pingback from  Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas

Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas wrote Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas
on Thu, Jan 1 2009 7:27 AM

Pingback from  Ship It Often vs. TDD - taccato! trend tracker, cool hunting, new business ideas

Patrick Smacchia [MVP C#] wrote Development Psychology, Technical debt and The next feature syndrome
on Sat, Feb 28 2009 9:46 PM

I would like to describe here a harmful scenario I have seen in many different occasions. Typically,

Community Blogs wrote Development Psychology, Technical debt and The next feature syndrome
on Sat, Feb 28 2009 10:28 PM

I would like to describe here a harmful scenario I have seen in many different occasions. Typically,

Patrick Smacchia [MVP C#] wrote My 100th blog post: Top 5 development practices you should care for
on Wed, Mar 25 2009 3:48 AM

This is a modest number but I am happy to have reached it, especially taking account that I spend weekly

Community Blogs wrote My 100th blog post: Top 5 development practices you should care for
on Wed, Mar 25 2009 3:59 AM

This is a modest number but I am happy to have reached it, especially taking account that I spend weekly

Lexus wrote re: Are you sure added and refactored code is covered by tests?
on Mon, Apr 13 2009 1:33 PM

Good site, admin.

Sancho wrote re: Are you sure added and refactored code is covered by tests?
on Tue, Apr 14 2009 1:56 PM

Good site, admin.

Shaun Davis wrote re: Are you sure added and refactored code is covered by tests?
on Thu, Apr 23 2009 1:11 AM

Hey just a heads up, I wanted to let everyone know that Xio Dibin speaks English.  I hope I posted in the right location?

Alexis wrote re: Are you sure added and refactored code is covered by tests?
on Sun, May 17 2009 2:43 PM

Good site, admin.

Hot wrote re: Are you sure added and refactored code is covered by tests?
on Sun, May 17 2009 7:25 PM

Good site, admin.

Panzer wrote re: Are you sure added and refactored code is covered by tests?
on Mon, May 18 2009 4:48 PM

Good site, admin.

Locker wrote re: Are you sure added and refactored code is covered by tests?
on Tue, May 19 2009 2:21 AM

Good site, admin.

Flash wrote re: Are you sure added and refactored code is covered by tests?
on Tue, May 19 2009 7:05 AM

Good site, admin.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Devlicio.us