【发布时间】:2016-12-07 20:25:31
【问题描述】:
我想用 asp.net core 和 xunit 测试我的服务。
这是我的服务:
public class MyService : IMyService
{
public int Add(int x, int y)
{
return x + y;
}
}
public interface IMyService
{
int Add(int x, int y);
}
我在 startup.cs 中注册了我的服务
services.AddTransient<IMyService, MyService>();
但是现在我如何获取实例并在测试项目中测试我的服务?
到目前为止,在我的测试项目中,我有:
public class Class1
{
IMyService myService;
[Fact]
public void PassingTest()
{
Assert.Equal(4, myService.Add(2,2));
}
}
【问题讨论】:
-
您到底想测试什么?
-
我在 MyService 类中的方法
-
然后新建一个实例并调用被测方法
-
我已经用我的解决方案更新了我的帖子,但它不起作用
标签: c# unit-testing asp.net-core .net-core xunit