对于集成测试 Asp.Net Core 应用程序,我们有Web应用程序工厂 https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-3.1#basic-tests-with-the-default-webapplicationfactory。但如何测试Worker
(HostedService
)那不是网络应用程序?我不想像下面那样复制 SUT 中的整个 DI 配置这个问题 https://stackoverflow.com/questions/51224146/integration-test-for-hosted-service-net-core。是否可以使用原始配置并覆盖一些依赖项,就像我们对 Web 应用程序所做的那样WebApplicationFactory.WithWebHostBuilder https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-3.1#customize-the-client-with-withwebhostbuilder?
我无法找到任何用于工作人员服务集成测试的解决方案,因此我采用了WebApplicationFactory
。源代码和使用示例可以在这里找到:https://github.com/gao-artur/WorkerService.Testing https://github.com/gao-artur/WorkerService.Testing
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)