c# - 单元测试 - 绑定(bind)程序集时忽略区域性

标签 c# .net unit-testing mstest

我对 C# 中的单元测试还很陌生。我使用 Visual Studio 添加了一个测试项目,但是当我尝试运行测试时,它们失败了,并提示程序集绑定(bind)失败。

所以我启用了日志记录并注意到测试正在尝试从特定于文化的目录(一个不存在的目录)加载我的 DLL。

例如如果测试项目的 DLL 存在于 C:\MyProject\ 中,它会在 C:\MyProject\en-GB\ 中查找被测程序集。

en-GB 的唯一引用是被测程序集的程序集文化属性。如果我将该属性的值更改为 en-US,则单元测试绑定(bind)程序会在 /en-US/

中搜索 DLL

我能以某种方式指定我不想要这种行为吗?

最佳答案

来自文档,

The attribute is used by compilers to distinguish between a main assembly and a satellite assembly. A main assembly contains code and the neutral culture's resources. A satellite assembly contains only resources for a particular culture, as in [assembly:AssemblyCultureAttribute("de")]. Putting this attribute on an assembly and using something other than the empty string ("") for the culture name will make this assembly look like a satellite assembly, rather than a main assembly that contains executable code. Labeling a traditional code library with this attribute will break it, because no other code will be able to find the library's entry points at runtime.

所以基本上,不要使用该属性。您实际上是在测试本地化的卫星组件吗?

关于c# - 单元测试 - 绑定(bind)程序集时忽略区域性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20959807/

相关文章:

unit-testing - 使用 PageObjects 测试具有嵌套在内部的复杂角度组件的组件

c# - 具有 "per-object"方法的语言的示例是什么?

c# - 如何在c#中使用带有 "not"的css选择器?

c# - .net 文档用 mshtml 写

c# - 为什么会发生 CLR 异常 FatalExecutionEngineError?

c# - Pechkin 和 IIS 中使用的进程

c# - 在 C# 中动态设置类的枚举属性

c# - 对于支持 FIPS 的系统,是否有替代 MD5 的哈希算法?

java - NPE 使用 mockito 进行单元测试

unit-testing - 尽管有测试失败,但运行 “cabal test” 通过