Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Excluding autogenerated code
openshac
#1 Posted : Tuesday, February 3, 2015 1:16:19 PM(UTC)
Rank: Member

Groups: Registered
Joined: 1/19/2015(UTC)
Posts: 14
Location: United Kingdom

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
What is the recommended way to exclude auto-generated code from NCrunch code-coverage?

At the moment I've got a number of classes that are generated using T4 Templates. The partial classes are currently preceded with the following standard Microsoft comments:

Quote:

//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
Remco
#2 Posted : Tuesday, February 3, 2015 9:50:19 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
Hi, thanks for posting.

At the moment, there is no feature that will let you handle this directly on a macro-level. You're welcome to request one on uservoice if you like.

There are some other options below that might get you close to what you are after:

- You can turn off the code coverage for an entire project/assembly by turning off the 'Instrument output assembly' project-level configuration setting
- It's possible to turn off code coverage using comments in the code. If its possible to change the auto generation template this could work well - http://www.ncrunch.net/documentation/concepts_code-coverage-suppression.
- If the generated code is all under the same namespace, you can exclude it from metrics aggregation in the Metrics Window so that it won't be applied to your metrics totals. I suggest this as I assume the reason you want to exclude this code is to remove its impact on your metrics.
openshac
#3 Posted : Wednesday, February 4, 2015 9:36:20 AM(UTC)
Rank: Member

Groups: Registered
Joined: 1/19/2015(UTC)
Posts: 14
Location: United Kingdom

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
Hi Remco,

I am generating the code myself so I think adding comments to the code will be the easiest solution. As I am currently just on an evaluation licence ATM I was trying to keep the code as NCrunch independent as possible, but this should be fine.

Thanks for your help.
Ralf Koban
#4 Posted : Wednesday, February 4, 2015 4:21:19 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/19/2014(UTC)
Posts: 44
Location: Germany

Thanks: 4 times
Was thanked: 10 time(s) in 9 post(s)
Hi,

we are using a similar approach (generating classes via T4 templates).
To exclude them from code coverage (not only NCrunch but also dotCover, MSTest, NCover, etc.), we add/generate the [ExcludeFromCodeCoverage] attribute to the generated classes.

Maybe that suits you as well.

BR,
Ralf
1 user thanked Ralf Koban for this useful post.
openshac on 2/4/2015(UTC)
openshac
#5 Posted : Wednesday, February 4, 2015 4:39:16 PM(UTC)
Rank: Member

Groups: Registered
Joined: 1/19/2015(UTC)
Posts: 14
Location: United Kingdom

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
Ralf,

That's exactly what I was looking for.

Cheers

Charlie
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.036 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download