Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data tests (DynamicDataAttribute) with readonly structs do not work (default is passed) #1693

Closed
gurustron opened this issue Jun 22, 2023 · 3 comments

Comments

@gurustron
Copy link

gurustron commented Jun 22, 2023

Describe the bug

If data test accepts readonly struct with fields (init prop will work) for some reason default struct is passed and not the actual value.

Steps To Reproduce

[DataTestMethod]
[DynamicData(nameof(TestDataDateOnly), DynamicDataSourceType.Method)]
public void TestDateOnly(DateOnly today, DateOnly inForceFrom)
{
	Assert.AreNotEqual(new DateOnly(),today);
	Assert.AreEqual(new DateOnly(2016, 4, 25),today);
}

public static IEnumerable<object[]> TestDataDateOnly()
{
	yield return new object[] { new DateOnly(2016, 4, 25), new DateOnly(2016, 4, 26)};
}
	
[DataTestMethod]
[DynamicData(nameof(TestDataCustomRecordStruct), DynamicDataSourceType.Method)]
public void TestCustomRecordStruct(MyStructField today)
{
	Assert.AreNotEqual(new MyStructField(),today);
	Assert.AreEqual(new MyStructField(2016),today);
}

public static IEnumerable<object[]> TestDataCustomRecordStruct()
{
	yield return new object[] { new MyStructField(2016)};
}
[DataTestMethod]
[DynamicData(nameof(TestDataCustomRecordStructProp), DynamicDataSourceType.Method)]
public void TestCustomRecordStructProp(MyStructProp today)
{
	Assert.AreNotEqual(new MyStructInitProp(),today);
	Assert.AreEqual(new MyStructProp(2016),today);
}

public static IEnumerable<object[]> TestDataCustomRecordStructProp()
{
	yield return new object[] { new MyStructProp(2016)};
}

// WORKS!	
[DataTestMethod]
[DynamicData(nameof(TestDataCustomRecordStructInitProp), DynamicDataSourceType.Method)]
public void TestCustomRecordStructInitProp(MyStructInitProp today)
{
	Assert.AreNotEqual(new MyStructInitProp(),today);
	Assert.AreEqual(new MyStructInitProp(2016),today);
}

public static IEnumerable<object[]> TestDataCustomRecordStructInitProp()
{
	yield return new object[] { new MyStructInitProp(2016)};
}

Expected behavior

All pass

Actual behavior

3 are failing (for DateOnly, MyStructField, MyStructProp)

Additional context

github repro
SO question

Workarounds

  • use record structs or init-only props
  • enclose data in custom wrapper class
@engyebrahim
Copy link
Member

Hi @gurustron !
I confirm the behaviour you mentioned, thanks for taking the time to add the issue.

@Evangelink
Copy link
Member

Hi @gurustron,

Your issue relates to the way MSTest serialize data to split test discovery and execution (for example in Visual Studio) and falls back under the bucket of this issue: #1462

@Evangelink
Copy link
Member

Closing this one, please follow #1462 to get notifications about the fix.

@Evangelink Evangelink closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants