[英]How can I use MEF to resolve dependencies during unit testing?
The component I'm developing has to interface with several external systems. 我正在开发的组件必须与多个外部系统交互。 I don't want to interact with the external systems when I'm running unit tests, just when we're doing integrated testing (or production, of course!) :-) In its most ugly-looking-form, it would be something along the lines of: 我不想在运行单元测试时与外部系统进行交互,而只是在我们进行集成测试(当然,就是生产!)时:-)在看起来最丑陋的形式中,类似于以下内容:
if (<Flag in App.config> == true)
{
// get result from external system
}
else
{
// get a mocked-up result
}
Is there an example of a better way to implement something like this using dependency injection so my code doesn't have to be polluted with IF-statements? 有没有一个更好的方法示例来使用依赖注入实现类似的东西,这样我的代码就不必被IF语句污染了? I was looking at using MEF because it's included in the .NET Framework. 我一直在使用MEF,因为它包含在.NET Framework中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.