Is it possible to use Dependency Injection with xUnit?

前端 未结 4 1222
忘掉有多难
忘掉有多难 2021-02-06 22:25

I have a test class with a constructor that needs an IService.

public class ConsumerTests
{
    private readonly IService          


        
4条回答
  •  北恋
    北恋 (楼主)
    2021-02-06 22:55

    There is a way to do this using nuget package out of this source code: https://github.com/dennisroche/xunit.ioc.autofac

    It works great as long as you use [Fact], but then I got blocked when started using [Theory]. There is a pull request to sort this out.

    To unblock myself, I used CollectionFixture to inject Container and from the container, I resolve the Interface.

提交回复
热议问题