DataRowAttribute Class

Definition

Attribute to define in-line data for a test method.

[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=true)]
public class DataRowAttribute : Attribute, Microsoft.VisualStudio.TestTools.UnitTesting.ITestDataSource
[<System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=true)>]
type DataRowAttribute = class
    inherit Attribute
    interface ITestDataSource
Public Class DataRowAttribute
Inherits Attribute
Implements ITestDataSource
Inheritance
DataRowAttribute
Attributes
Implements

Examples

[TestMethod]
  [DataRow(1,2)]
  [DataRow(2,2)]
  public void TestSomeNumbers (int x, int y)
  {
    Assert.AreEqual(x,y)
  }

Gives output:
Test Failed - TestSomeNumbers (1,2)
Test Passed - TestSomeNumbers (2,2)

You can also specify the test display name for each data row:

[TestMethod]
  [DataRow(1,2, DisplayName ="Sequential numbers")]
  [DataRow(2,2, DisplayName ="Equal numbers")]
  public void TestSomeNumbers (int x, int y)
  {
    Assert.AreEqual(x,y)       
  }

Gives output:
Test Failed - Sequential numbers
Test Passed - Equal numbers

Constructors

DataRowAttribute()

Initializes a new instance of the DataRowAttribute class.

DataRowAttribute(Object)

Initializes a new instance of the DataRowAttribute class.

DataRowAttribute(Object, Object[])

Initializes a new instance of the DataRowAttribute class which takes in an array of arguments.

Properties

Data

Gets data for calling test method.

DisplayName

Gets or sets display name in test results for customization.

Methods

GetData(MethodInfo)
GetDisplayName(MethodInfo, Object[])

Applies to