I have a SharePoint 2010 project in VS 2010, and I'm trying to develop some unit tests to test my code.
I have followed all of the instructions here to prepare my VS2010 environment to re-target the test project to .NET 3.5.
I generated a new test project by right-clicking in my SharePoint code, selecting "Create Unit Tests" and selecting the methods I wanted to test. I re-targeted the test project to .NET 3.5, enabled 64 bit testing, etc.
Now, when I try to run the tests, they fail with an error:
Warning: Test Run deployment issue: Failed to get the file for deployment item 'My.CodeToBeTested.dll' specified by the test 'My.TestProject.MyTestClass.MyTestMethod': System.IO.FileNotFoundException: Could not find file 'C:\Path\To\My\Project\My.CodeToBeTested.dll'.
It seems as though VS is looking for the .dll directly in the root folder of the project, instead of in the project\bin\debug folder.
Now, if I re-target the test project back to .NET 4.0, it deploys fine, and I can run tests that do not specifically use the SharePoint object model. But, obviously can't run tests that do use the SharePoint object model. So that's no good for me.
Also, I am unable to debug the tests when the test project is targeted to 3.5. It starts to run, and then kicks me out of debug mode and stops running, with no explanation.
Anyone know why targeting the test project to .NET 3.5 breaks VS's ability to locate the .dll? Or is preventing me from debugging?
EDIT 3/21/13
Ok, I demolished the test project and completely rebuilt it. I'm no longer getting the error where it seems that VS can't find my assembly to be tested. Instead, this is what's happening:
Whether I run the tests or try to debug them, all tests fail (and if debugging, no breakpoints are hit). When I look at the error message for why the tests fail, they all fail for the following reason:
MyTestProject.MyTestClass.MyTestMethod threw an exception: System.BadImageFormatException: Could not load file or assembly 'My.Assembly.ToBeTested_Accessor', Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
Now, keep in mind I have re-targeted the test project to .NET 3.5, and cleaned and rebuilt it several times. I have watched the My.Assembly.ToBeTested_Accessor.dll and .pdb files get removed from the /bin/Debug directory on cleaning the project, and manually deleted them from the /obj/Debug directory, and watched them both reappear upon rebuild - which is supposedly happening under .NET 3.5 - and yet I keep getting the same error.
I see a directory called Test References with a file called My.Assembly.ToBeTested.accessor in it, but all it has in that file is two lines:
My.Assembly.ToBeTested.dll
Desktop
and I can't see any way in the file properties to specifically re-target that file to .NET 3.5.
Does anyone know what is going on here, or how I can get these tests to run?
I'm starting to get a wee bit frustrated with this thing.