重定向程序集绑定是否适用于使用测试运行程序进行单元测试?

发布于 2024-07-13 02:24:46 字数 1493 浏览 11 评论 0原文

好的,这是我遇到的问题的完整描述:

我正在尝试使用 NUnit ExtensionMethods 但每当我使用 TestDriven.Net 运行包含其中一种扩展方法的测试时,或者如果我只是尝试使用测试运行程序 GUI(Icarus 或 NUnit)加载程序集,我都会收到 FileNotFoundException。

用头撞墙并进一步挖掘,我想我知道出了什么问题。 提示反射器,是的,我可以看到 NUnit.Framework>ExtensionMethods.dll 有一个引用

nunit.framework, Version=2.4.6.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77

,我当前包含的 nunit 版本是

nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77

现在我以前从未使用过程序集重定向,但它似乎是一个使用以下几行添加 App.Config 很简单:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <runtime>
        <assemblyBinding  xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity
                    name="nunit.framework.dll"
                    publicKeyToken="96d09a1eb7f44a77" />
                <bindingRedirect oldVersion="2.4.6.0" newVersion="2.4.8.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

据我了解,对 2.4.6 版本(本机上不存在)的调用应自动重定向到 2.4.8 版本。

但这不起作用,我怀疑(但尚未证实)这是因为测试运行程序不会自动读取 app.config 文件。

所以我的问题如下:

  1. 我对这个问题的诊断正确吗? 问题?

  2. 程序集重定向是 适当的解决方案,我正在做什么 对吗?

  3. 我如何让它与 测试运行程序?

Ok, so here's the full description of the problem I'm having:

I am trying to use NUnit ExtensionMethods but whenever I run a test containing one of the extension methods using TestDriven.Net or if I just flat out try to load the assembly using a test-runner GUI (Icarus or NUnit) I get a FileNotFoundException.

Pounding head against a wall and digging in further I think I know what's wrong. Cue reflector and yep, I can see that NUnit.Framework>ExtensionMethods.dll has a reference to

nunit.framework, Version=2.4.6.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77

and my current version of nunit that I'm including is

nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77

Now I have never used assembly re-direction before but it seems like it would be a simple matter of adding an App.Config with the following lines:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <runtime>
        <assemblyBinding  xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity
                    name="nunit.framework.dll"
                    publicKeyToken="96d09a1eb7f44a77" />
                <bindingRedirect oldVersion="2.4.6.0" newVersion="2.4.8.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

and it is my understanding that calls to the 2.4.6 version (which does not exist on this machine) should automatically redirect to the 2.4.8 version.

This does not work however, and I suspect (but have not yet confirmed) that this is because test runners do not automatically read app.config files.

So my question's are as follows:

  1. Am I right in my diagnosis of the
    problem?

  2. Is assembly redirection the
    appropriate solution and am I doing
    it right?

  3. How do I get this to work with the
    test runner?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落花浅忆 2024-07-20 02:24:46

如果您将配置设置放入正确的 .config 文件中,这应该可以工作。 哪一个取决于您用来运行测试的环境,但 NUnit 和 TestDriven.NET 都应该支持使用 testassemble.dll.config。
至于这是合适的解决方案,我会说是的。 唯一的其他可能性是使用发布者策略文件,但您需要用于编译 NUnit 的私钥。

This should work if you put the configuration settings in the correct .config file. Which one that is depends on the environment you are using to run the tests, but both NUnit and TestDriven.NET should support using testassembly.dll.config.
As for this is the appropriate solution, I would say yes. The only other possibility would be to use a publisher policy file, but you would need the private key used to compile NUnit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文