Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSTest Equivalent for NUnit's Parameterized Tests?

NUnit supports a feature where you can specify a set of data inputs for a unit test to be run multiple times.

[RowTest] [Row(1001,1,2,3)] [Row(1,1001,2,3)] [Row(1,2,1001,3)] public void SumTests(int x, int y, int z, int expected) {    ... } 

What's the best way to accomplish this same type of thing using MSTest? I can't find a similar set of attributes.

like image 624
blaster Avatar asked Mar 02 '10 21:03

blaster


People also ask

Which is better MSTest or NUnit?

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 the difference between MSTest and xUnit?

MSTest is concerned, the biggest difference between xUnit and the other two test frameworks (NUnit and MSTest) is that xUnit is much more extensible when compared to NUnit and MSTest. The [Fact] attribute is used instead of the [Test] attribute.

What is MSTest used for?

MSTest is Microsoft's tool used to run tests of . NET applications (in particular, it can be used for unit testing). In TestComplete, you can integrate your MSTest tests to your test projects and run them as part of your automated testing process.

Is MSTest a testing framework?

MSTest framework for Selenium automated testing is the default test framework that comes along with Visual Studio.


2 Answers

For those using MSTest2, DataRow + DataTestMethod are available to do exactly this:

[DataRow(Enum.Item1, "Name1", 123)] [DataRow(Enum.Item2, "Name2", 123)] [DataRow(Enum.Item3, "Name3", 456)] [DataTestMethod] public void FooTest(EnumType item, string name, string number) {     var response = ExecuteYourCode(item, name, number);      Assert.AreEqual(item, response.item); } 

More about it here

like image 138
Izzy Rodriguez Avatar answered Sep 20 '22 16:09

Izzy Rodriguez


Would this help?

This week I was adding some unit tests to a project that is managed by TFS, so I decided to use the "core" unit testing framework available with VS2008, and unfortunately it doesn't support RowTests. But it has a similar feature called Data-Driven Unit Test. With this approach it's a bit more complicate to implement the "simple" RowTest scenario, but it allows also to implement more complicate ones.

like image 43
Jorge Ferreira Avatar answered Sep 17 '22 16:09

Jorge Ferreira