AmirAdel
AmirAdel

Reputation: 45

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?

Upvotes: 3

Views: 817

Answers (1)

Mircea Matei
Mircea Matei

Reputation: 601

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.

Upvotes: 2

Related Questions