MSTest的TestMethod的依赖注入 [英] MSTest TestMethod Dependency Injection
问题描述
我使用的是DI容器,我想要做的MSTest的(VS 2010)单元测试与容器解决实例。
I'm using a DI container and I want to do MSTest (VS 2010) unit tests with instances resolved from the container.
我想获得这些实例注入到我的TestMethod的,或至少是我的TestClass。这可能吗?
I'd like to get these instances injected into my TestMethod or at least my TestClass. Is this possible?
现在我TestMethods直接调用 container.Resolve< T>(XXX)
,我想preFER避免让自己的注入测试是比较现实的。
Right now my TestMethods directly call container.Resolve<T>(xxx)
which I'd prefer to avoid so that my injection testing is more realistic.
任何人有这方面的经验?
Anyone have experience with this?
在此先感谢。
推荐答案
测试类的实例深深发生在的MSTest的框架,以便注入依赖到这将是一项艰巨的任务的内部类。
The instantiation of the test class happens deeply in the internal classes of the MSTest framework so injecting dependencies into it would be a challenging task.
这篇关于MSTest的TestMethod的依赖注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!