是否重定向程序集绑定的单元测试工作,测试跑步吗?绑定、重定向、单元测试、测试

2023-09-03 01:52:01 作者:拾你所爱

好了,所以这里的问题,我有充分的说明:

我想使用 NUnit的ExtensionMethods 但每当我运行包含的一个测试扩展方法使用TestDriven.Net或者如果我只是平了尝试使用一个测试亚军的GUI(伊卡洛斯或NUnit的),我得到一个FileNotFoundException异常加载程序集。

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

  nunit.framework,版本= 2.4.6.0,文化=中性公钥= 96d09a1eb7f44a77
 

和我目前的NUnit的是我,包括版本

  nunit.framework,版本= 2.4.8.0,文化=中性公钥= 96d09a1eb7f44a77
 

现在我从来没有使用汇编重新定向之前,但现在看来似乎是添加一个app.config有以下几行简单的事情:

 < XML版本=1.0编码=UTF-8&GT?;
<结构>
    <运行>
        < assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
            < dependentAssembly>
                < assemblyIdentity
                    NAME =nunit.framework.dll中
                    公钥=96d09a1eb7f44a77/>
                < bindingRedirect oldVersion =2.4.6.0NEWVERSION =2.4.8.0/>
            < / dependentAssembly>
        < / assemblyBinding>
    < /运行>
< /结构>
 
fiddler 代理实现移动端测试等配置

,这是我的理解是调用到2.4.6版本(未在本机上不存在)会自动重定向到2.4.8版本。

这不工作,但是我怀疑(但尚未证实),这是因为测试运行没有自动读取的app.config文件。

所以我的问题的情况如下:

我说的对我的诊断 问题?

在装配重定向     适当的解决方案,我在干嘛     对吗?

我如何得到这个与合作 测试运行?

解决方案

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

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:

Am I right in my diagnosis of the problem?

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

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

解决方案

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.

 
精彩推荐