0

Using Visual Studio 2019. The MSTest unit testing framework for C# has the DataRow attribute which allows test methods to be automatically called with multiple sets of constant input data. For example:

[TestMethod]
[DataRow(11.99, 4.55)] // One or more sets of constant input test data
[DataRow(50.00, 40.00)]
public void Debit_WithValidAmount_UpdatesBalance_WithConstantData(double balance, double debit)
{
    // ...method called twice with {11.99, 4.55} and {50.00, 40.00}
}

Is it possible to have multiple sets of constant test input data with Microsoft's Native Unit Test framework, also called the Microsoft Unit Testing Framework for C++?

MSTest also allows generator methods to create dynamic input data. For example:

[TestMethod]
[DynamicData(nameof(MyTestData), DynamicDataSourceType.Method)]
public void Debit_WithValidAmount_UpdatesBalance_WithDynamicData(double balance, double debit)
{
    // ...method called twice with {12.99, 1.23} and {55.00, 45.00}
}

private static IEnumerable<object[]> MyTestData()
{
    // Generator method to create dynamic test data
    yield return new object[] { 12.99, 1.23  };
    yield return new object[] { 55.00, 45.00 };
}

Similar question, is it possible to use generator methods with Microsoft's Native Unit Test framework to create dynamic input data?

drescherjm
  • 10,365
  • 5
  • 44
  • 64
AlainD
  • 5,413
  • 6
  • 45
  • 99

0 Answers0