microsoft / testfx

MSTest framework and adapter
MIT License
780 stars 259 forks source link

[DataTestMethod] is not allowed to be a Generic method #2402

Open mlsomers opened 9 months ago

mlsomers commented 9 months ago

Describe the bug

A test marked with the [DataTestMethod] attribute cannot have a generic parameter. It will not be recognized by the test runner.

Steps To Reproduce

[TestClass]
public class GTest
{
  [DataTestMethod]
  [DataRow((byte)10)]
  [DataRow((short)11)]
  [DataRow((long)12)]
  [DataRow((ulong)13)]
  public void GenericTest<T>(T value)
  {
    List<T> list = new List<T>(new[] {value});
    Assert.AreEqual<T>(value, list[0]);
  }
}

Expected behavior

The test framework should invoke the method of type T with the correct type of the given argument in DataRow.

Actual behavior

The test framework ignores the whole test.

Additional context

Ran into this limitation while migrating my LsMsgPack project from NUnit to MsTest. The last 100 or so tests in MpIntTest.cs are ignored. The old tests in Nunit are working.

Evangelink commented 9 months ago

Hi @mlsomers,

Generics are indeed not supported at the moment. Marking this as a feature request.

In the meantime, you will have to work with object.

Evangelink commented 3 days ago

@Youssef1313 could you please do a quick investigation on complexity there?

Youssef1313 commented 1 day ago

Assigning myself so that I don't forget. I'll validate how much work is needed here.