Search code examples
c#genericsmstest

Generic data-driven unit test in MSTest


I tried to write a Generic Test Method in c# for data-driven unit tests with MS Test. However, this method is not shown in the Test Explorer in VS 2019.

        [DataRow(new int[] { 1, 3 }, new int[] { 2 }, new int[] { 1, 2, 3 })]
        [DataTestMethod]
        public void MergeTwoGenericSortedArrays_Test<T>(T[] a1, T[] a2, T[] r)
            where T : IComparable<T>
        {
            var md = new MergeSortedArrays<T>();

            T[] m = md.Merge(a1, a2);

            CollectionAssert.AreEqual(r, m);
        }

Is it possible to write a test like this or I should find another way?


Solution

  • A generic method cannot be a test method. If you switch the Visual Studio Output to "Show output from:" Tests you will find some useful messages.