- vs中nuget 安装Microsoft.NET.Test.Sdk、xunit、xunit.runner.visualstudio
- xunit测试demo
public class HelloTest { //xunit提供默认输出接口 private readonly ITestOutputHelper _output; public HelloTest(ITestOutputHelper output) { _output = output; } [Fact] public void Test1() { _output.WriteLine("Hello"); } //InlineData,输入参数,可以多次 [Theory] [InlineData(1,2,3)] [InlineData(4, 5,8)] public void Test2(int a,int b,int expectedReuslt) { var addResult = this.add(a,b); _output.WriteLine($"arg1:{a},arg2:{b},actual Result:{addResult},expected Result:{expectedReuslt}"); Assert.Equal(addResult, expectedReuslt); } private int add(int a,int b) { return a + b; } }
- 测试结果