-
Notifications
You must be signed in to change notification settings - Fork 291
Closed as duplicate of#1462
Copy link
Description
Describe the bug
Given a struct with an implicit conversion to string (operator overload
public readonly struct AccountKind
{
private readonly string _value;
public AccountKind(string value) =>
_value = value;
public override string ToString() =>
_value;
public static implicit operator string(AccountKind obj) =>
obj.ToString();
public static implicit operator AccountKind(string str) =>
new AccountKind(str);
}And a test method which accepts it as a parameter via a [DynamicData] attribute:
[TestMethod]
[DynamicData(nameof(GetAccountKinds), DynamicDataSourceType.Method)]
public void TestMethod1(AccountKind kind)
{
Assert.IsNotNull(kind.ToString());
}
private static IEnumerable<object[]> GetAccountKinds()
{
yield return [new AccountKind("kind1")];
yield return [new AccountKind("kind2")];
yield return [new AccountKind("kind3")];
}What happens then:
- Test discovery generates only 1 test:
- Test execution passes a parameter with value
null:
Notes:
- This doesn't not happen when the assembly is decorated with
[TestDataSourceDiscovery(TestDataSourceDiscoveryOption.DuringExecution)]
- This does not happen when the parameter type is changed to
string(see the attached repro for an example)
- This does not happen when the parameter's type is
class
Steps To Reproduce
Attached a sample project: TestProject1.zip
Expected behavior
Test method is executed 3 times, each times receives a parameter with the correct value
Actual behavior
Test method is executed 1 time, it receives a parameter with null
Additional context
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.1" />VS 2022 version 17.11.5




