System.MissingMethodException: Method Not Found when running unit Tests
Lately, I have been doing Test Driven development in my development projects. I have noticed a strange issue which occurs especially when the code coverage is enabled for the assemblies. The result is , unit tests works normally in Debug mode and do not behave as expected when run in Normal mode.
I have noticed the bug logged for this on Connect website:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=123306
Meanwhile, the workaround for this is to do a full release build of the solution before running unit tests in Normal mode.I guess this is because, Normal run uses the release version of assemblies as opposed to Debug versions, and if the Release assemblies are either old or missing, they are bound to fail.
[Update 6/01/09]
Rory had left a comment on this post and provided the excellent and absolute solution for this. This is quoted in his own words and here is the link to his blog post. Thanks Rory !!!
The issue is encountered because the testrunconfig points code coverage at assemblies using a relative path that includes the build configuration output directory.
If the testrunconfig points to bin\Debug\YourAssembly.dll and you make a change to the methods in Debug and a test for it, then change to Release without a Debug build and run the unit tests, then the new tests won't find the methods in the assembly identified in the code coverage configuration.
See https://www.neovolve.com/post/2008/01/30/incorrect-code-coverage-references-in-testrunconfig.aspx
The fix is to manually edit the testrunconfig to replace the build configuration part of the path with $(OutDir). This will mean that the assemblies will work with any build configuration.
Comments
Anonymous
January 03, 2009
PingBack from http://www.codedstyle.com/systemmissingmethodexception-method-not-found-when-running-unit-tests/Anonymous
January 04, 2009
The issue is encountered because the testrunconfig points code coverage at assemblies using a relative path that includes the build configuration output directory. If the testrunconfig points to binDebugYourAssembly.dll and you make a change to the methods in Debug and a test for it, then change to Release without a Debug build and run the unit tests, then the new tests won't find the methods in the assembly identified in the code coverage configuration. See http://www.neovolve.com/post/2008/01/30/incorrect-code-coverage-references-in-testrunconfig.aspx The fix is to manually edit the testrunconfig to replace the build configuration part of the path with $(OutDir). This will mean that the assemblies will work with any build configuration.Anonymous
January 04, 2009
Thanks for the perfect solution Rory. I will update my post to include your solution and a link to your blog post as well :) Madhur