xunit 单元测试
代码:GitHub
参考地址:https://github.com/Acumatica/xunit.autofac
xunit +autofac进行单元测试
①创建一个类库
引用nuget:
xunit
xunit.runner.visualstudio 可以在vs中跑的包
xunit.autofac
②创建一个ServiceRegistration 类
public class ServiceRegistration : Module //Autofac
{
/// <summary>
/// 依赖注入
/// </summary>
/// <param name="builder"></param>
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<JwtUserRepository>().As<IJwtUserRepository>();
builder.RegisterType<JwtUserService>().As<IJwtUserService>();
}
}
在程序集中注册


添加测试类:
/// <summary>
/// Jwt用户表应用层服务测试
/// </summary>
public class JwtUserAppService_Test
{
/// <summary>
/// 依赖注入
/// </summary>
private readonly IJwtUserService _jwtUserService; public JwtUserAppService_Test(IJwtUserService jwtUserService)
{
this._jwtUserService = jwtUserService;
} /// <summary>
/// 全部用户
/// </summary>
/// <returns></returns>
[Fact]
public async Task GetListAsync_Test()
{
List<JwtUser> list = await this._jwtUserService.GetListAsync();
} /// <summary>
/// 用户名和密码获取用户
/// </summary>
/// <param name="inDto">inDto</param>
/// <returns>OutDto</returns>
[Fact]
public async Task GetJwtUserAsync_Test()
{
AuthenticateInDto inDto = new AuthenticateInDto
{
UserName = "sealee",
PassWord = ""
};
JwtUser model = await this._jwtUserService.GetJwtUserAsync(inDto);
} //添加删除修改,都需要新建一个类进行测试 }
}
打开测试:


xunit 单元测试的更多相关文章
- 用msbuild跑xunit单元测试
用了Visual Studio 2015之后,发现没法跑xUnit单元测试,xUnit.net runner不支持VS2015,TestDriven.Net也不支持VS2015. 等它们支持VS201 ...
- 轻松掌握VS Code开发.Net Core及创建Xunit单元测试
前言 本篇文章主要还是介绍使用 VS Code 进行.Net Core开发和常用 CLI命令的使用,至于为啥要用VS Code ,因为它是真的是好看又好用 :) ,哈哈,主要还是为了跨平台开发做准备. ...
- ABP Xunit单元测试 第五篇
1.创建如下的项目结构 public class TestName { public bool ValidateName(string Name) { if (Name == "yin&qu ...
- 使用xUnit为.net core程序进行单元测试(上)
一. 导读 为什么要编写自动化测试程序(Automated Tests)? 可以频繁的进行测试 可以在任何时间进行测试,也可以按计划定时进行,例如:可以在半夜进行自动测试. 肯定比人工测试要快. 可以 ...
- 使用xUnit为.net core程序进行单元测试(1)
导读 为什么要编写自动化测试程序(Automated Tests)? 可以频繁的进行测试 可以在任何时间进行测试,也可以按计划定时进行,例如:可以在半夜进行自动测试. 肯定比人工测试要快. 可以更快速 ...
- 使用 xUnit 编写 ASP.NET Core 单元测试
还记得 .NET Framework 的 ASP.NET WebForm 吗?那个年代如果要在 Web 层做单元测试简直就是灾难啊..NET Core 吸取教训,在设计上考虑到了可测试性,就连 ASP ...
- 使用 xUnit 编写 ASP.NET Core WebAPI单元测试
本文使用xUnit对ASP.NET Core WebAPI做单元测试,使用HttpClient的同步和异步请求,下面详细介绍xUnit的使用过程: 一.创建示例项目 模板为我们自动创建了一个Value ...
- xUnit入门一
看了下Nhibernate的入门Demo,感觉测试驱动开发会更效率.当然,你可能觉得不是还要额外编程单元测试代码吗?开发怎么会更效率? 一句话解释之,磨刀不误砍柴工. 那就开始入门吧 ~.~ 笔者使用 ...
- .NET Core 性能分析: xUnit.Performance 简介
xunit-performance 是xUnit的一个扩展, 使用它可以对.NET Core项目进行性能测试. 官网:https://github.com/Microsoft/xunit-perfor ...
随机推荐
- Java检查异常、非检查异常、运行时异常、非运行时异常的区别
Java把所有的非正常情况分为两种:异常(Exception)和错误(Error),它们都继承Throwable父类. Java的异常(Exception和Error)分为检查异常和非检查的异常. 其 ...
- matlab基础向7-8:画图
1.画直角坐标系的二维图 画直线: x1=[1 2 3]; y1=[4 5 6]; plot(x1,y1);%斜率为1的直线,穿过(1,4)(2,5)(3,6) 画抛物线y=x*x(-3<=x& ...
- CF1105D-Kilani and the Game-(多向bfs)
http://codeforces.com/problemset/problem/1105/D 题意:有一片矩阵区域,一开始有多个势力比如1,2,3,4....9,从势力1开始轮流向外扩张,地图上为‘ ...
- 第4章 Spring的数据库开发
4.1 Spring JDBC Spring的JDBC模块负责数据库资源管理和错误处理,化简了开发者对数据库的操作. 4.11 Spring JdbcTemplate的解析 * JdbcTemplat ...
- [React] Fetch Data with React Suspense
Let's get started with the simplest version of data fetching with React Suspense. It may feel a litt ...
- Unicode-objects must be encoded before hashing 错误解决办法
提交注册用户数据后出来这个,错误原因是update()必须指定要加密的字符串的字符编码 #encryptions1 = sha1()s1.update(upwd.encode("utf8&q ...
- openjudge1.1
目录 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.1.10 1.1.1 描述 对于大部分编程语言来说,编写一个能够输出"H ...
- LCA的多种求法(超详细!!!)
倍增求LCA (1)树上倍增法 预处理 设f[x,k]表示x的2^k辈祖先,即从x向根节点走2^k步到达的节点.特别地,若该节点不存在,则令f[x,k]=0.f[x,0]就是x的父节点.可以得出f[x ...
- 调用Fluent进行多工况计算总结
算例来源:https://confluence.cornell.edu/display/SIMULATION/FLUENT+-+Turbulent+Pipe+Flow 有时候我们对同一模型进行多工况计 ...
- 帝国cms替换iwms幻灯图片问题
在管理标签模板中增加一个新模板 页面模板内容为:[!--empirenews.listtemp--]<!--list.var1-->[!--empirenews.listtemp--] 列 ...