Why there are no stubs for interfaces in Microsoft.Fakes

I am going to use Microsoft.Fakes in my unit tests. I read a tutorial where Microsoft.Fakes creates a stub for the interface (embedded inside the solution), but in my stubs the solutions are available only for classes,

Can you tell me what to do in order to get stubs for all intercas too. Both interfaces and classes are defined as public.

+2
source share
2 answers

Fakes generate stubs for both classes and interfaces by default. You may have encountered one of the current limitations that makes Fakes skip your interface. To troubleshoot

  • open the .Fakes file and set the Verbosity attribute of the Fakes element to "Verbose"
  • open TOOLS β†’ Parameters β†’ Projects and solutions β†’ Assembling and starting and changing the output of MSBuild output to β€œDetails”
  • create a project containing the .Fakes file
  • open the output window and find the GenerateFakes task; analyze its output for information that explains why a particular interface was not muted.

In the upcoming quarterly update 1 of Visual Studio 2012, this information is reported as a warning in the error list window, regardless of the logging settings, which greatly facilitates troubleshooting.

+5
source

You may also not have collapsed into the appropriate namespace. Fakes are created in the same namespace as the interfaces in the assembly under test. So, for example, if you are testing MyApp.Validators.IRequestValidator, in the unit test you will need to use new MyApp.Validators.Fakes.StubIRequestValidator() , and not new MyApp.Fakes.StubIRequestValidator() .

+1
source

All Articles