Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio unit testing - multiple cases like Nunit

In Nunit one can reuse a test method for multiple cases.

[TestCase(12,3,4)]
[TestCase(12,2,6)]
[TestCase(12,4,3)]
public void DivideTest(int n, int d, int q)
{
  Assert.AreEqual( q, n / d );
}

How can I do this in Visual Studio's test framework?

like image 333
Colonel Panic Avatar asked Sep 12 '12 15:09

Colonel Panic


People also ask

How do you write multiple test cases in NUnit?

Make more copies of the attribute if you want multiple cases. The data type of the values provided to the TestCase attribute should match with that of the arguments used in the actual test case.

Which is better NUnit or MSTest?

The main difference is the ability of MsTest to execute in parallel at the method level. Also, the tight integration of MsTest with Visual Studio provides advantages in both speed and robustness when compared to NUnit. As a result, I recommend MsTest.

What is NUnit and MOQ?

NUnit is a unit testing framework for . NET languages, and Moq is the most popular mocking framework for . NET. I assume the reader is familiar with C# projects, Visual Studio IDE, and the Nuget package manager for managing dependencies.

Can we use MOQ with NUnit?

The advantages of using Moq is, we can unit test the code successfully without using an external dependency object in the test code. Conclusion: NUnit and Moq are the suitable frameworks for testing the MVC Model layer.


2 Answers

It is not possible out of the box. But for VS 2010 atleast you can write MSTEST Extensions to provide nearly the same feature. Check this blog. But it is not nearly as good as NUnit's TestCase.

like image 72
Ganesh R. Avatar answered Oct 26 '22 03:10

Ganesh R.


Unfortunately, MS Test doesn't support RowTests. However, a workaround can be hacked using the DataSource attribute. There is an example here.

like image 44
StuartLC Avatar answered Oct 26 '22 05:10

StuartLC