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);
}
}
|