Why there are no stubs for interfaces in Microsoft.Fakes

こ雲淡風輕ζ 提交于 2019-12-10 11:07:54

问题


I'm about to use Microsoft.Fakes in my unit tests. I read a tutorial where Microsoft.Fakes creates a stub for an interface (implementred inside the solution), but in my solution stubs are available only for classes.

Can you tell me what should I do to get stubs also for all the intercaes. Both interfaces and classes are defined as public.


回答1:


Fakes generates stubs for both classes and interfaces by default. You may have bumped into one of the current limitations, which is causing Fakes to skip your interface. To troubleshoot,

  • open the .Fakes file and set Verbosity attribute of the Fakes element to "Verbose"
  • open TOOLS -> Options -> Projects and Solutions -> Build and Run and change MSBuild output verbosity to "Detailed"
  • build the project that contains the .Fakes file
  • open the Output window and search for the GenerateFakes task; review its output for information that explains why a particular interface was not stubbed.

In the upcoming Quarterly Update 1 of Visual Studio 2012, this information reported as warnings in the Error List window, regardless of the logging settings, which should make troubleshooting much easier.




回答2:


You may also not have drilled down to the proper namespace. The Fakes are generated in the same namespace as the interfaces are in in your assembly under test. So, for example, if you're testing MyApp.Validators.IRequestValidator, in your unit test, you'll have to use new MyApp.Validators.Fakes.StubIRequestValidator() as opposed to new MyApp.Fakes.StubIRequestValidator().



来源:https://stackoverflow.com/questions/13051775/why-there-are-no-stubs-for-interfaces-in-microsoft-fakes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!