Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
638 views
in Technique[技术] by (71.8m points)

c# - MSTest Equivalent for NUnit's Parameterized Tests?

NUnit supports a feature where you can specify a set of data inputs for a unit test to be run multiple times.

[RowTest]
[Row(1001,1,2,3)]
[Row(1,1001,2,3)]
[Row(1,2,1001,3)]
public void SumTests(int x, int y, int z, int expected)
{
   ...
}

What's the best way to accomplish this same type of thing using MSTest? I can't find a similar set of attributes.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For those using MSTest2, DataRow + DataTestMethod are available to do exactly this:

[DataRow(Enum.Item1, "Name1", 123)]
[DataRow(Enum.Item2, "Name2", 123)]
[DataRow(Enum.Item3, "Name3", 456)]
[DataTestMethod]
public void FooTest(EnumType item, string name, string number)
{
    var response = ExecuteYourCode(item, name, number);

    Assert.AreEqual(item, response.item);
}

More about it here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...