简体   繁体   English

dotnet test - 覆盖.net核心配置的可能性

[英]dotnet test - possibility to override .net core configuration

Can the configuration values in an .net core application be overriden when executing tests through "dotnet test" (for example using AddCommandLine extension like you would use it when doing "dotnet run". 通过“dotnet test”执行测试时,是否可以覆盖.net核心应用程序中的配置值(例如使用AddCommandLine扩展,就像在执行“dotnet run”时一样使用它)。

More info: 更多信息:

Tests do some integration testing through which Startup.cs is also executed from the asp.net core project, and I would like to override a configuration value there. 测试执行一些集成测试,通过它也可以从asp.net核心项目执行Startup.cs,我想在那里覆盖配置值。

You should create an interface and a wrapper class to deal with the appsettings and either mock your interface or use fakes for your test project. 您应该创建一个接口和一个包装类来处理appsettings并模拟您的界面或使用假的测试项目。 then you will be able to control what you need to set as appsettings while testing 然后,您将能够控制在测试时需要设置为appsettings的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM