I had been having some serious grief with Visual Studio’s unit testing tools. VS was complaining that some tests did not exist, and others called methods that didn’t exist. Both claims were total lies as all methods in question existed, and could be found by using the “Navigate to” feature in VS.
I had two basic errors when I tried to run tests. One was of the form “Method TestProject.SystemsRepositoryTest.CreateNewCamera does not exist” when the method did exist. I could right-click the test in the Test Results window and choose “Open test” and it would take me there. However, when trying to run the test, VS claimed it didn’t exist.
The other error I got was of the form “Test method TestProject.SystemsRepositoryTest.GetAllCameras threw exception: System.MissingMethodException: Method not found: ‘System.Collections.ObjectModel.ObservableCollection`1
Thanks to these problems, I have wasted loads of time debugging things that could have been fixed with unit testing. It has been frustrating to say the least!
Well, I finally found the answer…
I opened the bin/Debug folder in the test project in Windows Explorer and deleted everything in it. I then rebuilt the test project, and my tests ran fine.
For some odd reason, it looks like rebuilding the test project wasn’t actually changing the DLLs in the folder, so it was using old versions, in which the methods didn’t exist. Deleting them all forced VS to grab fresh copies of the referenced DLLs, and rebuild the test project’s DLL.
I don’t know if this is a bug in Visual Studio 2010, but it doesn’t seem to be a feature that I would have added in by choice!