MSTest的TestMethod的依赖注入MSTest、TestMethod

2023-09-04 01:20:59 作者:你爹。

我使用的是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.

 
精彩推荐
图片推荐