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 ...
随机推荐
- typename T::SubType * ptr;
#include <iostream> using namespace std; template<class T> class MyClass{ public: typena ...
- 使用tensorflow时,关于GPU的设置
查看显卡使用情况: nvidia-smi 设置tensorflow按需分配资源: import os os.environ["CUDA_DEVICE_ORDER"] = " ...
- vue element-ui 饿了么布局,gutter间距碰上bordr 会失效
//如下情况,gutter间距会失效 <el-row :gutter="20"> <el-col :span="12" style=" ...
- For 32-bit BOOL is a signed char, whereas under 64-bit it is a bool.
https://stackoverflow.com/questions/31267325/bool-with-64-bit-on-ios/31270249#31270249 Definition of ...
- MongoDB远程连接-命令行客户端mongo.exe
命令行客户端mongo.exe 位于安装目录bin子目录下.MongoDB的所有可执行程序都在其中. 双击打开mongo.exe应该是默认连接本地数据库服务,因此需要用Cmd或Powershell的方 ...
- 验证码破解 | Selenium模拟登陆微博
模拟登陆微博相对来说,并不难.验证码是常规的5个随机数字字母的组合,识别起来也比较容易.主要是用到许多Selenium中的知识,如定位标签.输入信息.点击等.如对Selenium的使用并不熟悉,请先移 ...
- Python -- seek定位文件指针位置 错误 io.UnsupportedOperation: can't do nonzero cur-relative seeks错误
f=open("E:/test/悯农.txt",'r') str=f.read(17) print("读取的数据是:",str) position=f.tell ...
- space-cloud 学习一 基本试用
space-cloud 是一个支持多数据库,以下是一个简单的基于官方文档的试用 使用docker-compose 运行 环境准备 下载docker-compose文件 wget https://raw ...
- PHP Record the number of login users
Function to record how many times the user logs in Connect to the database first: you can create a n ...
- GoCN每日新闻(2019-11-02)
GoCN每日新闻(2019-11-02) GoCN每日新闻(2019-11-02) 1. Go 1.13.4 and Go 1.12.13 are released https://groups.go ...