public class Arithmetic{ public int Add(int nb1, int nb2) { return nb1 + nb2; }}
using Xunit; public class Arithmetic_Tests{ [Fact]//需要在测试方法加上特性Fact public void Add_Ok() { Arithmetic arithmetic = new Arithmetic(); var sum = arithmetic.Add(1, 2); Assert.True(sum == 3);//断言验证 }}
Theory][InlineData(2, 3, 5)][InlineData(2, 4, 6)][InlineData(2, 1, 3)] //对应测试方法的形参public void Add_Ok_Two(int nb1, int nb2, int result){ Arithmetic arithmetic = new Arithmetic(); var sum = arithmetic.Add(nb1, nb2); Assert.True(sum == result);}