I have a test that uses predefined MemberData and the Theory attribute. NCrunch executes and reports on the tests correctly, but the reports for code coverage do not reflect this.
Remco NCrunch Developer
#7135
27 Mar 2015 22:30 UTC
Can you describe what kind of behaviour you're seeing? Is it that the coverage is showing only for one of the theory sub-tests?
Also - can you confirm which version of Xunit you're running?
Also - can you confirm which version of Xunit you're running?
Edited 27 Mar 2015 22:31 UTC
I think I am seeing the same issue myself so perhaps I can provide more information. It's not a big issue, just affects the code coverage report.
The problem is that in an xunit / nCrunch combination the MemberData used for a test in included in the code coverage report.
Therefore, you'll get less than 100% code coverage even if you have tested every method of every class.
For example, the static values below are all black circles in the sidebar (no coverage) whilst the test referencing the data has green circles.
It would be nice to get my code coverage to 100%, there may be another way of specifying the source test data that will enable this.
The problem is that in an xunit / nCrunch combination the MemberData used for a test in included in the code coverage report.
Therefore, you'll get less than 100% code coverage even if you have tested every method of every class.
For example, the static values below are all black circles in the sidebar (no coverage) whilst the test referencing the data has green circles.
public static IEnumerable<object[]> GoodLocationsKeyValueData()
{
yield return new object[] { "aplacename" };
yield return new object[] { "a-placename" };
yield return new object[] { "a-place-name" };
yield return new object[] { "a-four-part-name" };
yield return new object[] { "another four part name" };
}
[Theory]
[MemberData(nameof(GoodLocationsKeyValueData))]
public void Place_names_are_parsed_as_ok(string source)
{
var status = addressQualityChecker.StatusGuessFromSourceQuality(source);
Assert.Equal(AddressQualityStatus.OK, status);
}It would be nice to get my code coverage to 100%, there may be another way of specifying the source test data that will enable this.
Edited 04 Aug 2018 15:18 UTC
Remco NCrunch Developer
#12489
04 Aug 2018 23:35 UTC
Hi, thanks for sharing these details.
This is behaviour as designed, because the code inside the GoodLocationsKeyValueData method isn't actually part of any test. Mechanically, this code is being treated as an extension of the test framework itself. It's meta code used to 'discover' the tests.
If you're concerned about how this makes your reports look, I'd suggest placing code coverage suppression comments around it. For example:
//ncrunch: no coverage start
public static IEnumerable<object[]> GoodLocationsKeyValueData()
{
yield return new object[] { "aplacename" };
yield return new object[] { "a-placename" };
yield return new object[] { "a-place-name" };
yield return new object[] { "a-four-part-name" };
yield return new object[] { "another four part name" };
}
//ncrunch: no coverage end
This is behaviour as designed, because the code inside the GoodLocationsKeyValueData method isn't actually part of any test. Mechanically, this code is being treated as an extension of the test framework itself. It's meta code used to 'discover' the tests.
If you're concerned about how this makes your reports look, I'd suggest placing code coverage suppression comments around it. For example:
//ncrunch: no coverage start
public static IEnumerable<object[]> GoodLocationsKeyValueData()
{
yield return new object[] { "aplacename" };
yield return new object[] { "a-placename" };
yield return new object[] { "a-place-name" };
yield return new object[] { "a-four-part-name" };
yield return new object[] { "another four part name" };
}
//ncrunch: no coverage end
Post a reply
Log in to reply.