2

I am trying to run a test case like the one mentioned below in Microsoft Test Manager. I created a test case in MTM under a test suite and attached the below created test case in the automation script.

public class Calculator
{
    public int Add(int a, int b)
    {
        return a + b;
    }
}

[TestMethod]
[DataRow(3, 4, 7)]
[DataRow(5, 6, 11)]
public void When_add_two_numbers(int firstNumber, int secondNumber, int expectedResult)
{
    //Arrange
    Calculator calc=new Calculator();

    //Act
    var actualResult = calc.Add(firstNumber, secondNumber);

    //Assert
    Assert.AreEqual(expectedResult,actualResult);
}

Because MSTest now supports DataTestMethod and DataRow attributes then I expect such data driven tests to be able to run on MTM as well. Is it not supported by MTM? If not then what is the workaround?

I am getting below error when I am trying to run this test case in MTM.

"Method" does not have correct signature. Test method marked with the [TestMethod] attribute must be non-static, public, does not return a value and should not take any parameter. for example: public void Test.Class1.Test().

Nkosi
  • 235,767
  • 35
  • 427
  • 472

1 Answers1

0

You need to replace [TestMethod] by [DataTestMethod]

[DataTestMethod] //<-- THIS IS REQUIRED
[DataRow(3, 4, 7)]
[DataRow(5, 6, 11)]
public void When_add_two_numbers(int firstNumber, int secondNumber, int expectedResult) {
    //...
}

so that test methods can have parameters and uses them to parametrize the test.

Nkosi
  • 235,767
  • 35
  • 427
  • 472