MSTest exception: Unit Test Adapter threw exception: Type is not resolved for member

匿名 (未验证) 提交于 2019-12-03 08:41:19

问题:

In my project I write tests using Microsoft's unit testing framework. All of my tests pass when I run them from Visual Studio but when I run the tests from MSBuild all of the tests fail with the following erorr message:

Unit Test Adapter threw exception: Type is not resolved for member SomeType,SomeAssembly Version=assemblyVersion, Culture=neutral, PublicKeyToken=..

The assembly not found is a 3rd party assembly referenced by all of the projects.

The build script is used by TFS so I've aded the following lines:

<RunTest>true</RunTest>  <ItemGroup>     <MetaDataFile Include="$(BuildProjectFolderPath)myproject.vsmdi">         <TestList>CI_Tests</TestList>     </MetaDataFile> </ItemGroup> 

I've found the this post that shows a solution to this issue but unfortunatly I cannot chnage the files on the TFS server.

Help!

回答1:

The first thing to check would be if this assembly is copied to the folder from which msbuild runs the tests. It might be the case that you have a copy in your bin/Debug folder because of some historic reasons, but the dependency is not set up properly in the project.



回答2:

I encountered the same problem in my unit tests. The linked article above indicates that the problem is that VSTS causes copying of some objects in the thread's CallContext.

For what it's worth, in my case the problem was that I had manually placed an object in the thread's CallContext, which caused this exception. I was able to resolve this by clearing the CallContext in my TestCleanup routine. I didn't have to change any files anywhere.



回答3:

I had also run into the same issue but where I had StructureMap initialisation being performed within the constructor for a base test class.

I was able to get around the problem by moving the call from the constructor to the [TestInitialize] method. I also ensured that the [TestCleanUp] method disposed of the created StructureMap container. After this MSBuild (2010) would run through the tests without raising this error.



回答4:

Had this error

Unit Test Adapter threw exception:  Type is not resolved for member 'NHibernate.HibernateException,NHibernate 

As it turned out the problem was in exception thrown in static constructor for the test. It was completely unrelated to the looks of message and was happening during DB creation using BuildSchema.

Very uninformative error message by MSTest which cost me a lot of hours and stress. putting migration to something better like NUnit in our TODO list.



回答5:

This article solved my problem with this error:

To recap, MyCustomException was thrown at very early stage of test execution. The dll that contained it was not loaded yet so Unit Test Adapter indeed could not reach it.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!