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

Notification

Icon
Error

TestCaseSource won't mark the source data as covered.
GreenMoose
#1 Posted : Tuesday, January 15, 2013 4:21:03 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 503

Thanks: 142 times
Was thanked: 66 time(s) in 64 post(s)
[1.43.0.23]
Code:
[TestFixture]
    public class TestFixture 
    {
        private string[] _data
        {
            //Not covered
            get { return new[] {"a", "b", "c"}; }
        }

        [Test, TestCaseSource("_data")]
        public void Test(string data)
        {
            //Covered
            Console.WriteLine("Data: {0}", data);
        }
    }
Known issue? Are there any workarounds?
Thanks.
Remco
#2 Posted : Tuesday, January 15, 2013 9:38:32 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,986

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi, thanks for posting!

This is behaviour by design. The _data property is queried outside the scope of the test, as NUnit uses this property in order to analyse and identify the test (which is a step that occurs prior to any execution). If this is messing with your coverage metrics and making your code look bad, I recommend suppressing the coverage for this property with an '//ncrunch: no coverage' comment.


Cheers,

Remco
GreenMoose
#3 Posted : Wednesday, January 16, 2013 7:59:35 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 503

Thanks: 142 times
Was thanked: 66 time(s) in 64 post(s)
Why would one want this behavior? It is covered as I would have expect with other covering tools and I would prefer avoid placing ncrunch comments in code when I utilize functionality of NUnit.

Are there any plans making this at least as an option (i.e. so I do get coverage on TestCaseSource data)?

Thanks.
Remco
#4 Posted : Wednesday, January 16, 2013 9:25:25 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,986

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
The behaviour is designed according to technical constraints. There is no test that actually owns the coverage of the _data property - it is executed during the analysis step when the test framework uses reflection to discover tests.

For the lines to be covered, they would need to be somehow assigned to a particular test (i.e. the fixture, or some kind of placeholder). The effort involved in doing this is significant, as analysis-time behaviour within NCrunch is very different to run-time behaviour, so unfortunately I don't see this changing any time soon. Sorry.
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.035 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download