Net Core: Execute All Dependency Injection in Xunit Test for AppService, Repository, etc

后端 未结 3 1507
暖寄归人
暖寄归人 2020-11-28 11:37

I am trying to implement Dependency Injection in Xunit test for AppService. Ideal goal is to run the original application program Startup/configuration, and use any depende

3条回答
  •  死守一世寂寞
    2020-11-28 11:41

    When you are testing. You need to use mocking libraries or Inject your service directly on contructor ie.

    public DBContext context;
    public IDepartmentAppService departmentAppService;
    
    /// Inject DepartmentAppService here
    public DepartmentAppServiceTest(DepartmentAppService departmentAppService)
    {
        this.departmentAppService = departmentAppService;
    }
    

提交回复
热议问题