使用 NUnit 在不同的应用程序域中运行单元测试 [英] Run unit tests in different appdomain with NUnit

查看:23
本文介绍了使用 NUnit 在不同的应用程序域中运行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎遇到了一个问题,我们正在使用的应用程序使用 Ninject 内核,并且包含一个特定的配置,该配置与 WCF 调用的内容(用户名、令牌...)一起收集.

I seem to be having an issue, the application we're using uses a Ninject kernel, and contains a particular configuration that's gathered with contents of the WCF call (username, token...).

基于特定配置为用户分配了应用程序的权限,这通过 Ninject 内核中的特定实例进行屏蔽.

Based on that a particular configuration the user is assigned rights on the app, this is shielded through a particular instance in the Ninject kernel.

我们不能仅仅重构 Ninject 内核,我们想做的是运行几个 Nunit 测试,而是在单独的应用程序域中运行每个测试(每次使用不同的设置重新创建内核).

We cannot just recompose the Ninject kernel, what we'd like to do is run a couple of Nunit tests, but run each of them in a separate app domain (recreating the kernel each time with different settings).

我只找到了在不同应用程序域中运行整个测试项目的方法,但没有找到针对每个测试进行测试的方法.

I've only found ways to run whole test projects in different app domains but not test per test.

有没有办法解决这个问题?

Is there a way to solve this?

不幸的是,Ninject 配置不在我们这边,我们必须以这种方式忍受"它.

Unfortunately the Ninject configuration is not on our side, we have to 'live' with it this way.

推荐答案

我不认为有一种方法可以在不重写部分 NUnit 代码的情况下解决它.自从我进入 NUnit 代码以来已经有一段时间了,但我很确定主应用程序域加载部分没有改变.

I don't think there is a way to solve it without re-writing parts of the NUnit code. It has been a while since I've been inside the NUnit code, but I am pretty sure the main app domain loading part has not changed.

NUnit 通常使用两个应用程序域.运行 NUnit 时创建的默认程序集和一个单独的程序集,用于加载测试程序集及其引用的程序集.这样做的主要原因是允许卸载测试组件.你不能卸载一个dll,但你可以卸载一个应用程序域.

NUnit typically uses two app domains. The default one that is created when NUnit is run and a separate one to load the test assemblies and the assemblies they reference. It's main reason in doing this is to allow the unloading of the test assemblies. You can't unload a dll, but you can unload an appdomain.

您可能可以在每次测试时运行一次 NUnit 并在命令行上通过测试,但这很丑陋,我不确定它会有所帮助.

You might be able to run NUnit once per test and pass the test on the command line, but that's ugly and I'm not sure it will help.

也可以利用 Action AttributesNUnit 2.6,但您将在其中做大量工作.

It might also be possible to leverage Action Attributes in NUnit 2.6, but you are going to do a lot of work in there to do it.

您还可以在设置方法中创建一个新的应用域,并在每次测试中调用它.尴尬但可能.

You might also be able to create a new app domain in your setup method and call into it in each test. Awkward but possible.

对不起,我没有更完整的答案.

I'm sorry I don't have a more complete answer.

这篇关于使用 NUnit 在不同的应用程序域中运行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆