![[xUnit]尝试单元测试 [xUnit]尝试单元测试](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
参考:
http://shouldly.readthedocs.org/en/latest/
创建测试项目工程,类型选择类库,在NuGet中搜索xunit并添加xUnit.net,搜索xunit.runner.visualstudio添加xUnit.net[Runner:Visual Studio],搜索shouldly添加Shouldly,打开测试窗口,菜单栏测试 -> 窗口 -> 测试资源管理器。
(参考http://xunit.github.io/docs/getting-started-desktop.html)
public class Class1
{
[Fact]
public void PassingTest()
{
//Assert.Equal(4, Add(2, 2));
Add(, ).ShouldBe();
} int Add(int x,int y)
{
return x + y;
}
}
上面的测试方法添加标记属性[Fact],断言采用了Shoudly和Assert(被注释的)两种方式。
测试流程采用A(Arrange布局)A(Act动作)A(Assert断言),Arrange提供被测函数的运行环境,Act运行被测试函数,Assert判断运行结果。
Shoudly是一个断言框架,是对xUnit的Assert类的封装,优化了测试窗口中显示的信息。
关键字:.NET,xUnit