开发者

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

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>
    <Meta开发者_如何学JAVADataFile 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!


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.


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.


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.


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.


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.


Happening when the assemblies been tested have loaded instances of their class marked as [Serializable]. Workaround by deriving from MarshalByRefObject so the deserialization is no longer attempted from mstest host.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜