14

It's easy to add a Microsoft Fakes assembly to a test project: just right click on the parent assembly in the references section and choose "Add Fakes Assembly". However, when the parent assembly public interface changes (new interfaces, new methods), the Fakes Assembly becomes out of date.

When I right click on the parent assembly again, I'd love to see "Replace Fakes Assembly" or "Update Fakes Assembly", but all I see is "Add Fakes Assembly".

Choosing "Add Fakes Assembly" when the Fakes assembly has already been added results in an error:

Fakes assembly already referenced. A Fakes assembly for is already in the reference list. Remove the .Fakes reference and try again.

After following the instructions, then choosing "Add Fakes Assembly", the same error occurs.

I can resolve this by deleting the corresponding xml file in the Fakes directory (.fakes).

So, I have to manually delete two items (the fakes assembly and the fakes xml file) before I can successfully update the fakes assembly.

Is there an easier or more straightforward way to do this?

2
  • Does cleaning the solution after removing the reference work? Would that be easier? Jan 11, 2013 at 20:43
  • Cleaning the solution has no effect. Jan 11, 2013 at 20:51

1 Answer 1

14

The Fakes code generator automatically detects changes in visible API of the target assembly and regenerates the fakes assembly when necessary. When the target assembly changes, simply build the test project that contains its .Fakes file.

2
  • 2
    Armed with the confidence of this answer, I was able to find that there was a typo that made it appear that the fakes assembly was out of date even though it was not. Jan 11, 2013 at 21:36
  • The question as asked is still relevant in other cases; for instance, when adding a .fakes file "as a link", the detection of when the file has changed fails, and the fakes assembly is not rebuilt when you modify the linked-to file. Hence, after adding to the .fakes file, you have to manually do the steps mentioned to remove the fakes reference and file, and then re-add them in order to rebuild the fakes assembly. Apr 9, 2018 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.