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

Notification

Icon
Error

Code coverage issue for XUnit
AlanLTF
#1 Posted : Friday, March 27, 2015 1:31:35 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/26/2015(UTC)
Posts: 3
Location: United States of America

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
#2 Posted : Friday, March 27, 2015 10:30:49 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,328

Thanks: 700 times
Was thanked: 866 time(s) in 824 post(s)
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?
ryanoneill1970
#3 Posted : Saturday, August 4, 2018 3:17:35 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/29/2015(UTC)
Posts: 3
Location: United Kingdom

Thanks: 1 times
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.

Code:

                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.
Remco
#4 Posted : Saturday, August 4, 2018 11:35:34 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,328

Thanks: 700 times
Was thanked: 866 time(s) in 824 post(s)
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
1 user thanked Remco for this useful post.
ryanoneill1970 on 8/5/2018(UTC)
Users browsing this topic
Guest (2)
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.024 seconds.