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

Notification

Icon
Error

BUG: DynamicData does not work properly for class with null test
TKrueger
#1 Posted : Monday, February 4, 2019 11:51:25 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/4/2019(UTC)
Posts: 9
Location: Germany

Thanks: 4 times
Was thanked: 1 time(s) in 1 post(s)
Code:

public class SomeImplementation : ISomeImplementation
{
	public bool DoSomething()
	{
		return true;
	}
}

[TestClass, TestCategory("NCrunch.DynamicData")]
public class ImplementationDynamicDataTest
{
	/*
	 * NCrunch analyse process dies at test with class variables provided as null input:
	 * 
	 * An error occurred while analysing this project after it was built: System.NullReferenceException: Object reference not set to an instance of an object.
	 * at System.Object.GetType()
	 * at nCrunch.Module.MSTest.Integration.MSTestDynamicDiscoverer.<createDynamicDataSourceTests>b__7_0(Object p)
	 * at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
	 * at nCrunch.Module.MSTest.Integration.MSTestDynamicDiscoverer.createDynamicDataSourceTests(List`1 frameworkTests, IMSTestParameterSupplier parameterSupplier, ReflectedMethod method, ReflectedType fixture, Factory testNameFactory)
	 * at nCrunch.Module.MSTest.Integration.MSTestDynamicDiscoverer.<>c__DisplayClass5_0.<FindFrameworkTestsInAssembly>b__1()
	 * at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
	 * at nCrunch.Module.MSTest.Integration.MSTestDynamicDiscoverer.FindFrameworkTestsInAssembly(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, ComponentUniqueName testComponentUniqueName, PlatformType platformType, DynamicProxy[] dynamicProxies)
	 * at nCrunch.TestExecution.TestFinder.<>c__DisplayClass2_2.<FindTestsForFrameworks>b__2()
	 * at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
	 * at nCrunch.TestExecution.TestFinder.<>c__DisplayClass2_0.<FindTestsForFrameworks>b__0()
	 * at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
	 * at nCrunch.TestExecution.TestFinder.FindTestsForFrameworks(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, DescribedTestFrameworkDiscoverer[] describedDiscoverers, ComponentUniqueName testComponentUniqueName, PlatformType platformType, DynamicProxy[] dynamicProxies)
	 * at nCrunch.TestExecution.RemoteTaskRunner.AnalyseAssembly(DescribedTestFrameworkDiscoverer[] applicableFrameworks, ComponentUniqueName testComponentUniqueName, PerfTracker perfTracker)
	 * 
	 */

	public static IEnumerable<object[]> DoSomethingTestData
	{
		get
		{
			yield return new object[] {null, false, "Missing implementation" };
			yield return new object[] { new SomeImplementation(), true, "Implementation executed" };
		}
	}

	public class ImplementationContainer
	{
		public SomeImplementation Implementation { get; set; }
	}

	public class ClassUnderTest
	{
		public bool Execute(ImplementationContainer container)
		{
			return container?.Implementation?.DoSomething() ?? false;
		}
	}

	[DataTestMethod]
	[DynamicData(nameof(DoSomethingTestData), DynamicDataSourceType.Property)]
	public void DoSomethingTest(SomeImplementation implementation, bool expected, string description)
	{
		var container = new ImplementationContainer
		{
			Implementation = implementation
		};

		var classUnderTest = new ClassUnderTest();

		classUnderTest.Execute(container).Should().Be(expected, description);
	}
}
Remco
#2 Posted : Monday, March 4, 2019 10:18:30 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
1 user thanked Remco for this useful post.
TKrueger on 3/6/2019(UTC)
TKrueger
#3 Posted : Wednesday, March 6, 2019 8:21:23 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/4/2019(UTC)
Posts: 9
Location: Germany

Thanks: 4 times
Was thanked: 1 time(s) in 1 post(s)
Hello,

I tried the new version in my test project. There the test has now been successfully completed.

Unfortunately I have determined an other issue in my main application which relates to the current issue.

I have updated my test project and can reproduce the issuse with the following adjustment:

Code:

[DataTestMethod]
[DynamicData(nameof(DoSomethingTestData), DynamicDataSourceType.Property)]
public void DoSomethingWithObjectsTest(SomeImplementation implementation, bool expected, string description)
{
       implementation.Should().NotBeNull();
       // or this (make no difference)
       //Assert.IsNotNull(implementation);
}


Now I get this message:
Quote:

NCrunch: The test cases for this test cannot be reported individually by NCrunch because at least one of the parameters being supplied is not a primitive type. For full test case decomposition under NCrunch, all test case parameters must be of primitive types.


Can you please also check this problem?

Thanks
Remco
#4 Posted : Wednesday, March 6, 2019 10:22:29 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
TKrueger;13178 wrote:
Now I get this message:
Quote:

NCrunch: The test cases for this test cannot be reported individually by NCrunch because at least one of the parameters being supplied is not a primitive type. For full test case decomposition under NCrunch, all test case parameters must be of primitive types.


Can you please also check this problem?

Thanks


In this case, the message you're seeing is behaviour by design.

For NCrunch to decompose a dynamic method into multiple test cases, it needs to be able to uniquely identify the parameters for each test case and serialize them between environments. It isn't really possible to do this reliably with user types (which can only be uniquely identified by memory address), so we just roll up the test cases into a single test and report it in the same way as VSTest does.
TKrueger
#5 Posted : Wednesday, March 6, 2019 12:03:51 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/4/2019(UTC)
Posts: 9
Location: Germany

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

I have checked my issue again and have to say "sorry my mistake".
1 user thanked TKrueger for this useful post.
Remco on 3/6/2019(UTC)
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.042 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download