DataTestMethod and DataRow attributes in MSTEST
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 build with them.
Does anyone know anything about these attributes or how to get them working?
[DataTestMethod] [DataRow("a", "b")] [DataRow(" ", "a")] public void TestMethod1(string value1, string value2) { Assert.AreEqual(value1 + value2, string.Concat(value1, value2)); }
I know this is an old question, but there is now a good walkthrough published at
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).
DataTestMethod and DataRow attributes in MSTEST, You can set as many [DataRow] attributes as you want. Also you need to replace [TestMethod] by [DataTestMethod] : [TestClass] public class type DataRowAttribute = class inherit Attribute interface ITestDataSource Public Class DataRowAttribute Inherits Attribute Implements ITestDataSource Inheritance
Finally, this feature has been added (still in pre-release)
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
DataRowAttribute Class (Microsoft.VisualStudio.TestTools , These attributes are provided by MSTest, so they are naturally supported by the MSTest runner in Visual Studio, and by ReSharper. Note also the There are other MSTest attributes that enable you to write a suite of similar tests. A DataTestMethod attribute represents a suite of tests that execute the same code but have different input arguments. You can use the DataRow attribute to specify values for those inputs.
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.
MSTest v2: Data tests, I discovered today that [DataRow] can be used with together with [TestMethod], where I had the understanding that [DataTestMethod] was required. I've find no practical difference between the two attributes in the source You can easily create a lots of unit tests using parametrized tests. The 2 attributes DataRow and DynamicData should be enough for most of the cases. The data tests are extensibles, so you can create your own attributes to create your own data source. Of course, you can combine the 3 methods for the same test method.
Using DataTestMethod and DataRow to pass parameters to a unit , Description After upgrading MSTest to MSTest v2, there is an extra test I have 8 tests with the DataTestMethod attribute, which correlates with I've find no practical difference between the two attributes in the source code, but the documentation for [DataTestMethod] says that it is intended for data driven tests. Then the examples for [DataRow] uses [TestMethod] .
Most Complete MSTest Unit Testing Framework Cheat Sheet, With it, you can create a DataTestMethod, with DataRows for each test. of the TestMethod attribute, it is decorated with the DataTestMethod The MSTest project is also supported with another attribute which enables us to write a suite for a similar test. DataTestMethod attributes represent a suite of tests which executes the same code with different input arguments. A DataRow attribute can be used for specifying the values for those inputs.
DataTestMethod vs TestMethod · Issue #64 · microsoft/testfx-docs , Apart from the inline DataRow attributes you can use the DynamicData to use a test cases provided by a property or method. Here we have.