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: 4
Location: Germany

Thanks: 1 times
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);
	}
}
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.019 seconds.