【问题标题】:nunit version 3 not able to test code involving dynamic generation of assembliesnunit 版本 3 无法测试涉及动态生成程序集的代码
【发布时间】:2018-05-11 14:07:54
【问题描述】:

场景:作为逻辑的一部分,系统生成如下动态程序集。

CompilerParameters cp = new CompilerParameters();

cp.GenerateExecutable = false;
cp.GenerateInMemory = true;

cp.TreatWarningsAsErrors = false;
cp.ReferencedAssemblies.Add("Employee.dll");
cp.ReferencedAssemblies.Add("Person.dll");

CompilerResults cr = provider.CompileAssemblyFromSource(cp, "someCode");
if (cr.Errors.Count > 0)
{..}

我在 NUnit-Gui-0.6.0 中打开单元测试程序集并测试一个方法,该方法最终将上述代码作为业务逻辑的一部分调用。

问题:Above Error Count 大于 0 并有以下消息:

error CS0006: Metadata file 'Person.dll' could not be found
error CS0006: Metadata file 'Employee.dll' could not be found

我已验证这些程序集与单元测试 DLL 一起存在于 bin 目录中。此代码适用于常规应用程序工作流程,但不适用于 NUnit 3.*。

环境详情:VS 2017. Unit Test DLL and Application DLLs are full .NET Framework 4.7.1.

不确定这是 NUnit 3.* 中的错误还是应用程序问题。

问候,

伊夫蒂哈尔。

【问题讨论】:

    标签: c# nunit


    【解决方案1】:

    你在编译单元测试项目时使用哪种配置模式?当您选择“调试”配置模式时,dll 文件默认输出到 bin\Debug 文件夹。由于您说您的程序集在 bin 文件夹中,请检查您是否没有将程序集放在 bin\Debug 文件夹中。

    【讨论】:

    • 我尝试过调试和发布模式。我认为这不是问题,因为其他不涉及动态编译的单元测试通过而没有任何错误。我怀疑在您提到的场景中我们会收到“无法找到程序集”。
    猜你喜欢
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-18
    • 1970-01-01
    • 1970-01-01
    • 2015-05-16
    相关资源
    最近更新 更多