当我运行所有测试时单元测试失败,但在调试时通过 [英] Unit Tests failing when I Run All Tests but pass when I Debug

查看:199
本文介绍了当我运行所有测试时单元测试失败,但在调试时通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Visual Studio 2017中使用NUnit3并进行TDD.自从我更新代码以使最新的测试通过以来,确实发生了一些奇怪的事情.

I'm using NUnit3 in Visual Studio 2017 and doing TDD. Something really strange is happening since I updated my code to make my latest test pass.

现在,当我单击运行所有测试"时,其他三个测试都失败了,如下所示:

Now, 3 of my other tests are failing when I click Run All Tests, as below:

这告诉我Assert方法中的实际值和预期值不相等.

It is telling me that the actual and expected values in my Assert method are not equal.

但是,当我在Assert方法所在的行上放置一个断点并开始调试时,stacktrace显示期望值和实际值相同,然后测试通过,如下所示:

However, when I put a breakpoint at the line where the Assert method is and start debugging, the stacktrace is showing that expected and actual are the same value and then the test passes, as below:

我是不是在做一些愚蠢的事情,或者是VS2017或NUnit中存在错误?

Am I doing something stupid or could there be a bug in VS2017 or NUnit or something?

这会发生在其他任何人身上吗?

This ever happen to anyone else?

推荐答案

失败的测试共享一个资源,这些资源在一起测试时会影响它们.重新检查受影响的测试及其主题.

The failing tests share a resource that affects them all when tested together. Recheck the affected tests and their subjects.

您还应该查看主题中的静态字段或属性.如果在设计类时使用不当,它们往往会引起问题.

You should also look into static fields or properties in the subjects. They tends to cause issues if not used properly when designing your classes.

这篇关于当我运行所有测试时单元测试失败,但在调试时通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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