1

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?

2
  • I suggest you read this issue, it might help you. Commented Feb 15, 2023 at 9:04
  • Is there a VS feature suggestion for that to vote ? Still needed Commented Nov 5, 2023 at 15:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.