I have a visual studio 2008 Unit test and I'm getting the following runtime error:
Unable to set TestContext property for the class JMPS.PlannerSuite.DataServices.MyUnitTest. Error: System.ArgumentException: Object of type 'Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapterContext' cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'
I have read that VS 2008 does not properly update the references to the UnitTestFramework when converting 2005 projects. My unit test was created in 2008 but it inherits from a base class built in VS 2005. Is this where my problem is coming from? Does my base class have to be rebuilt in 2008? I would rather not do this as it will affect other projects.
In other derived unit tests built in 2005, all that we needed to do was comment out the TestContext property in the derived unit test. I have tried this in the VS 2008 unit test with no luck. I have also tried to "new" the TestContext property which gives me a different runtime error.
Any ideas?
I had the same problem in Visual Studio 2012 when I upgraded an older project (i think 2005).
The Reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework needs to be removed by right clicking it in the Solution Explorer then removing it.
To add the right one:
I'm posting this here in the hopes that it helps someone unit testing a smart device project. I got a very similar error when I first tried to run a unit test for a method in a smart device project I was working on in Visual Studio 2008:
Error: System.ArgumentException: Object of type 'Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapterContext' cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'
Googling the error returned results that suggested it was caused by upgrading a test project from Visual Studio 2005 format to 2008, and that the reference to the UnitTestFramework.dll was still for the old version (8.0) and required updating. This did not apply to me as I had not upgraded my test project from VS2005. So I continued searching.
After hours of searching for other causes for the error without success, I stumbled upon the following references in the smart device project:
Visual Studio was obtaining these references from the following folder:
C:\Program Files\Windows Mobile 5.0 SDK R2\Managed Libraries
However, the smart device project's target platform was the Windows Mobile 6 Professional SDK. I didn't notice this before as I did not originally create the smart device project. So I removed the references to the two DLLs and readded them from the following folder:
C:\Program Files\Windows Mobile 6 SDK\Managed Libraries
After rebuilding the smart device project, running the test method succeeded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With