Last active
October 31, 2022 20:01
-
-
Save nikanos/3196db9afd95856ac41cd0a70d8898e1 to your computer and use it in GitHub Desktop.
MSTest DataTestMethod & DataRow example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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