DataTestMethod and DataRow attributes in MSTEST

天大地大妈咪最大 提交于 2019-11-30 07:51:35

I know this is an old question, but there is now a good walkthrough published at https://blogs.msmvps.com/bsonnino/2017/03/18/parametrized-tests-with-ms-test/

In a nutshell, you will need to install MSTest.TestFramework and MSTest.TestAdapter, and remove references to Microsoft.VisualStudio.QualityTools.UnitTestFramework. You can then indicate a parameterised test with the [DataTestMethod] attribute, and can add your parameters using the [DataRow] attribute, as per your example. The values from the [DataRow] attribute will be passed to the test method in the order in which they are specified.

Note that the values in the [DataRow] attribute must be primitives, so you can't use a DateTime or decimal for example. If you want them, you will have to work around this limitation (e.g. instead of having a DateTime parameter to represent a date, you could have three integer parameters representing year, month and day, and create the DateTime within the test body).

Finally, this feature has been added (still in pre-release) https://blogs.msdn.microsoft.com/visualstudioalm/2016/06/17/taking-the-mstest-framework-forward-with-mstest-v2/

Basically, one has to do two things:

1) Install two NuGet packages (versions don't really matter, but this is what I have)

  <package id="MSTest.TestAdapter" version="1.1.5-preview" targetFramework="net452" />
  <package id="MSTest.TestFramework" version="1.0.6-preview" targetFramework="net452" />

2) Remove the refenrece to the old test library, because it has the same attributes defined in the same namespaces - this was done to achieve backwards compatibility

Microsoft.VisualStudio.QualityTools.UnitTestFramework

It appears this is only available within the unit testing project for WinRT/Metro and now with update 2, Windows Phone 8. It's a mystery to my why this is not available for all testing with mstest.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!