Open sharwell opened 4 years ago
@sharwell What's the recommended way to avoid the direct construction in tests?
Hey an appropriate mef container and request the type from it.
@CyrusNajmabadi I am not sure to get what you just explained, any example?
Sure. in lots of tests you'll have something more like:
Here, instead of instantiating this type directly, we retrieve it using mef from the mef container we have for tests to use.
Here, instead of instantiating this type directly, we retrieve it using mef from the mef container we have for tests to use.
👍 Yep! This ensures that all test code operating on ICodeActionEditHandlerService
(from this example) is operating on the same instance of ICodeActionEditHandlerService
, which is the same behavior the application has at runtime. The analyzers related to MEF construction provide a much stronger relation between test behavior and production code behavior.
This issue tracks MEF exports that suppress RS0033 (Importing constructor should be [Obsolete]) for cases where the part is directly constructed in test code.