DataTestMethod and DataRow attributes in MSTEST

后端 未结 3 1216
耶瑟儿~
耶瑟儿~ 2020-12-25 10:05

I have seen in a Microsoft video about Visual Studio update 2 regarding these attributes. However, I can\'t find any other information about them and can\'t get a project to

3条回答
  •  长情又很酷
    2020-12-25 10:40

    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).

提交回复
热议问题