Build/Test Issues

TestCaseSource won't mark the source data as covered.

Started by GreenMoose on 6,358 views

[1.43.0.23]
[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.

Edited

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
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.
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.

Post a reply

Log in to reply.