简体   繁体   English

Mstest单元测试从命令行失败

[英]Mstest unit tests fail from command line

I have written a unit test that uses the testsettings file to deploy some referenced dll in the OUT folder. 我编写了一个单元测试,它使用testsettings文件在OUT文件夹中部署一些引用的dll。 I run my unit test using this command. 我使用这个命令运行我的单元测试。

"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe" 
"/testcontainer:C:\Unittests\unit_test.dll" 
"/runconfig:C:\Unittests\unit_test_settings.testsettings" 
"/resultsfile:C:\Unittests\unit_test_results.trx"

Some tests in my unit test run fine but some fail with the following error. 我的单元测试中的一些测试运行正常,但有些测试失败并出现以下错误。

Failed object initialization (ISupportInitialize.EndInit). 对象初始化失败(ISupportInitialize.EndInit)。 The satellite assembly named "some_referenced_dll.resources.dll, PublicKeyToken=" for fallback culture "en" either could not be found or could not be loaded. 名为“some_referenced_dll.resources.dll,PublicKeyToken =”的后备文化“en”的附属程序集无法找到或无法加载。 This is generally a setup problem. 这通常是一个设置问题。 Please consider reinstalling or repairing the application. 请考虑重新安装或修复该应用程序。
System.Resources.MissingSatelliteAssemblyException: The satellite assembly named... System.Resources.MissingSatelliteAssemblyException:名为...的附属程序集

In an attempt to fix this, I added the some_referenced_dll.resouce.dll as a deployment Item in the testsettings file but that didn't help. 为了解决这个问题,我在testsettings文件中添加了some_referenced_dll.resouce.dll作为部署项,但这没有帮助。

I can see that the dlls are getting copied in the OUT folder. 我可以看到dll被复制到OUT文件夹中。

Also the tests are running fine from VS 2012 after I add the some_referenced_dll.dll as a reference to the project. 在我添加some_referenced_dll.dll作为项目的引用之后,测试在VS 2012中运行良好。

MORE INFO: 更多信息:

There are tests that are using some other dll as refrence directly (say ref_dll_2.dll) and passing. 有些测试直接使用其他dll作为参考(比如ref_dll_2.dll)和传递。 This ref_dll_2.dll is also in the OUT folder. 此ref_dll_2.dll也位于OUT文件夹中。

I am facing the problem with a dll (some_referenced_dll.resouce.dll) that is not directly referenced from my test. 我遇到的问题是dll(some_referenced_dll.resouce.dll)没有直接从我的测试中引用。 My unit test calls into some dev code which inturn tries to initializes a class which fails. 我的单元测试调用了一些dev代码,它试图初始化一个失败的类。

Would be make sense to forcefully load a dll? 强行加载dll会有意义吗? Is there a way to do that? 有没有办法做到这一点?

OK so I finally fixed the problem. 好的,所以我终于解决了这个问题。 Documenting here for completeness. 在此记录完整性。

The problem was that my MSTEST unit test could not find the resource/satellite assembly (some_referenced_dll.resources.dll) and was thus throwing the exception. 问题是我的MSTEST单元测试找不到资源/附属程序集(some_referenced_dll.resources.dll),因此抛出异常。 I was using the deploymentItem attribute to deploy the dll (some_referenced_dll.dll) but not the resource dll. 我使用deploymentItem属性来部署dll(some_referenced_dll.dll)但不是资源dll。 The solution was to use the deploymentItem and deploy the resource dll (some_referenced_dll.resources.dll) as well. 解决方案是使用deploymentItem并部署资源dll(some_referenced_dll.resources.dll)。

Bill Wang provided an excellent answer in this thread that helped solve the problem. Bill Wang在这个帖子中提供了一个很好的答案,帮助解决了这个问题。 It was a simple fix for a really irritating problem. 对于一个非常恼人的问题,这是一个简单的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM