gpt4 book ai didi

c# - Mstest 单元测试从命令行失败

转载 作者:行者123 更新时间:2023-11-30 16:56:58 24 4
gpt4 key购买 nike

我编写了一个单元测试,它使用 testsettings 文件在 OUT 文件夹中部署一些引用的 dll。我使用此命令运行我的单元测试。

"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"

我的单元测试中的一些测试运行良好,但一些测试失败并出现以下错误。

Failed object initialization (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. This is generally a setup problem. Please consider reinstalling or repairing the application.
System.Resources.MissingSatelliteAssemblyException: The satellite assembly named...

为了解决这个问题,我在测试设置文件中添加了 some_referenced_dll.resouce.dll 作为部署项,但这没有帮助。

我可以看到 dll 正在 OUT 文件夹中复制。

在我添加 some_referenced_dll.dll 作为对项目的引用后,测试从 VS 2012 运行良好。

更多信息:

有些测试直接使用其他一些 dll 作为引用(比如 ref_dll_2.dll)并通过了。此 ref_dll_2.dll 也在 OUT 文件夹中。

我正面临一个 dll (some_referenced_dll.resouce.dll) 的问题,它不是直接从我的测试中引用的。我的单元测试调用了一些开发代码,这些代码又尝试初始化一个失败的类。

强行加载一个dll有意义吗?有办法吗?

最佳答案

好的,所以我终于解决了这个问题。为了完整起见,在此处记录。

问题是我的 MSTEST 单元测试找不到资源/附属程序集 (some_referenced_dll.resources.dll),因此抛出异常。我使用 deploymentItem 属性来部署 dll (some_referenced_dll.dll) 而不是资源 dll。解决方案是使用 deploymentItem 并同时部署资源 dll (some_referenced_dll.resources.dll)。

Bill Wang 在此 thread 中提供了出色的答案这有助于解决问题。这是一个非常恼人的问题的简单修复。

关于c# - Mstest 单元测试从命令行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27270147/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com