NUnit has a feature called Values, like below:
[Test]
public void MyTest(
[Values(1,2,3)] int x,
[Values("A","B")] string s)
{
// ...
}
This means that the test method will run 6 times:
MyTest(1, "A")
MyTest(1, "B")
MyTest(2, "A")
MyTest(2, "B")
MyTest(3, "A")
MyTest(3, "B")
We're using MSTest now, is there any equivalent for this so that I can run the same test with multiple parameters?
[TestMethod]
public void Mytest()
{
// ...
}
MSTest has a powerful attribute called DataSource, using this you can perform data driven test as you asked. You can have your test data in XML, CSV or in a database. Here are few links that will guide you
http://visualstudiomagazine.com/articles/2009/09/15/unit-testing-with-vsts2008-part-3.aspx http://msdn.microsoft.com/en-us/library/ms182527.aspx
http://msdn.microsoft.com/en-us/library/ms243192.aspx
Hope this will help you.
MsTest does not support that feature but you can implement your own attribute to achieve that. have a look at the below:
http://blog.drorhelper.com/2011/09/enabling-parameterized-tests-in-mstest.html
It's very simple to implement - you should use
TestContext
property andTestPropertyAttribute
.Example
I couldn't get The
DataRowAttribute
to work in Visual Studio 2015, this is what I ended up with:The real solution here is to just use NUnit (unless you're stuck in MSTest like I am in this particular instance).
This feature is in pre-release now and works with VS 2015.
For example:
EDIT 4: Looks like this is completed in MSTest V2 June 17, 2016: https://blogs.msdn.microsoft.com/visualstudioalm/2016/06/17/taking-the-mstest-framework-forward-with-mstest-v2/
Original Answer:
As of about a week ago in Visual Studio 2012 Update 1 something similar is now possible:
EDIT: It appears this is only available within the unit testing project for WinRT/Metro. Bummer
EDIT 2: The following is the metadata found using "Go To Definition" within Visual Studio:
EDIT 3: This issue was brought up in Visual Studio's UserVoice forums. Last Update states:
https://visualstudio.uservoice.com/forums/330519-team-services/suggestions/3865310-allow-use-of-datatestmethod-datarow-in-all-unit