由于 AppDomain 在项目之间进行交叉时,通过 Resharper 8 运行 NUnit 测试失败 [英] Running NUnit through Resharper 8 tests fail when crossing between projects due to AppDomain

查看:30
本文介绍了由于 AppDomain 在项目之间进行交叉时,通过 Resharper 8 运行 NUnit 测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新到 Resharper 8,当我尝试运行一套项目时.这些测试包含两套集成测试,它们都使用 IISExpress 来运行网站、发出 Web 请求并检查响应.

I recently updated to Resharper 8, and when I tried to run a suite of projects. These tests contain two suites of integration tests that both use IISExpress to run a website, make web requests and check the responses.

单独运行它们是成功的,并且运行所有测试之前都会成功.但是,升级后要运行的第二组测试将失败.

Running them in isolation is successful, and running all the tests would previously succeed. However, after the upate the second set of tests to run would fail.

调查显示 AppDomain.CurrentDomain.BaseDirectory 继续作为要运行的第一个测试而不是更改.由于集成测试由两个项目组成,这会导致第二个项目失败,因为它找不到任何所需的配置文件.

Investigation has revealed the AppDomain.CurrentDomain.BaseDirectory is staying as the first test to run instead of changing. Since the integration tests are composed of two projects, this is causing the second project to fail since it cannot find any of the configuration files needed.

我在 Resharper 8 中找不到禁用这种不同行为的任何选项,这似乎是 /domain:Single nunit 标志的行为.除了降级到 Resharper 7,有人知道解决方案吗?这是 Resharper 8 的预期行为还是错误?

I cannot find any option to disable this different behaviour in Resharper 8, which appears to be the behaviour of the /domain:Single nunit flag. Short of downgrading to Resharper 7, does anybody know a solution to this? And is it an intended behaviour of Resharper 8 or a bug?

推荐答案

解决方法:

您是否尝试过在 Visual Studio 中使用 ReSharper -> 选项 -> 工具 -> 单元测试

Have you tried in Visual Studio going to ReSharper -> Options -> Tools -> Unit Testing

将设置并行运行最多 1 个程序集"更改为更高的数字.我为每个测试项目尝试了一个.我认为最大是核心数.

Change the setting "Run up to 1 assemblies in parallel" to a higher number. I tried one for each test project. Max is number of cores, I think.

我知道有悖常理,但它对我有用,我在失败的测试中使用 AppDomain.CurrentDomain.BaseDirectory

Counterintuitive I know, but it worked for me and I am using AppDomain.CurrentDomain.BaseDirectory in the failing tests

原因ReSharper 8 中的缓存优化错误.工作目录设置不正确.也许并行运行会为每个测试创建一个单独的进程,因此它们不会被彼此的设置绊倒.

The Cause A caching optimization bug in ReSharper 8. Working Directory is not set properly. Perhaps running in parallel creates a separate process for each test, so they don't trip over each other's settings.

修复JetBrains 声称这将在 8.0.1 版本中修复

The Fix JetBrains claim that this will be fixed in version 8.0.1

更新:Resharper 8.1 中添加了一个新的单元测试选项来适应这种情况.在 ReSharper -> 选项 -> 工具 -> 单元测试 -> "对每个程序集使用单独的 AppDomain 进行测试.

Update: There is a new unit testing option added in Resharper 8.1 to accomodate this scenario. Find it at ReSharper -> Options -> Tools -> Unit Testing -> "Use Separate AppDomain for each assembly with tests.

这篇关于由于 AppDomain 在项目之间进行交叉时,通过 Resharper 8 运行 NUnit 测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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