Skip to content

Instantly share code, notes, and snippets.

@nikanos
Last active October 31, 2022 20:01
Show Gist options
  • Save nikanos/3196db9afd95856ac41cd0a70d8898e1 to your computer and use it in GitHub Desktop.
Save nikanos/3196db9afd95856ac41cd0a70d8898e1 to your computer and use it in GitHub Desktop.
MSTest DataTestMethod & DataRow example
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace MSTestDataTestMethodSample
{
[TestClass]
public class NumberCheckerTests
{
[TestMethod]
[DataTestMethod]
[DataRow(1)]
[DataRow(100)]
[DataRow(Int32.MaxValue)]
public void Test_IsPositiveWithPositiveNumber_ReturnsTrue(int num)
{
Assert.IsTrue(NumberChecker.IsPositive(num));
}
[TestMethod]
[DataTestMethod]
[DataRow(Int32.MinValue)]
[DataRow(-100)]
[DataRow(-1)]
[DataRow(0)]
public void Test_IsPositiveWithNonPositiveNumber_ReturnsFalse(int num)
{
Assert.IsFalse(NumberChecker.IsPositive(num));
}
}
public class NumberChecker
{
public static bool IsPositive(int num)
{
return num > 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment