相当于mstest中的assert.warning?
MbUnit 中是否有 Assert.Warning 的 MsTest 等效项?
is there a MsTest Equivalent of Assert.Warning in MbUnit ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
MbUnit 中是否有 Assert.Warning 的 MsTest 等效项?
is there a MsTest Equivalent of Assert.Warning in MbUnit ?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
最接近的匹配是
Assert.Inconclusive()
- 它不会使测试失败,但也不会成功。它属于第三阶段,称为“不确定”。单个不确定的测试将导致整个测试套件变得不确定。
还有一些重载也支持自定义消息:
The closest match is
Assert.Inconclusive()
- it doesn't make the test fail as such, but it doesn't succeed either. It fall into a third stage called Inconclusive.A single Inconclusive test will cause an entire test suite to be Inconclusive.
There are overloads that supports custom messages as well:
当我在某些项目中使用 NUnit 时,我遇到了类似的问题。尝试使用
I have a similar issue as I use NUnit for some projects. Try using
您可能想要使用自定义异常。
Assert.Inconclusive 的问题是测试资源管理器指出测试甚至没有运行。在将来运行测试时,这可能会产生误导,特别是当测试由其他开发人员运行时:
我更喜欢的方式如下。首先,定义一个自定义的
UnitTestWarningException
。我给了我一个额外的构造函数,这样我就可以传递带有参数的 String.Format 样式的警告消息:然后,在您想要以警告结束单元测试的地方,抛出一个
UnitTestWarningException
相反:结果:测试资源管理器然后显示测试已执行,但失败并出现
UnitTestWarningException
,显示警告:You may want to use a custom exception.
The trouble with Assert.Inconclusive is that Test Explorer states the test wasn't even run. This may be misleading when running the test in the future, particularly if the test is run by other developers:
The way I've come to prefer is as follows. Firstly, define a custom
UnitTestWarningException
. I've given mine an additional constructor so I can pass my warning message String.Format-style with arguments:Then, at the point where you want to end a unit test with a warning, throw a
UnitTestWarningException
instead:The result: Test Explorer then shows that the test has been executed, but failed with a
UnitTestWarningException
that shows your warning:这是我关于如何使用 nunit 发出警告的黑客(我知道这个问题是关于 mstest 的,但这也应该有效)。一如既往,我对任何改进都很感兴趣。这个方法对我有用。
背景:我有代码检查测试本身是否有正确的注释,并具有逻辑来检测是否有人在不更改注释的情况下复制并粘贴了另一个测试。这些是我希望向开发人员显示的警告,而正常的 Assert.Inconclusive 不会阻止实际测试的运行。有些专注于测试,清理重构阶段是删除警告。
任务:在运行所有其他断言后发出警告。这意味着甚至会在开发过程中的测试中通常出现的 Assert.Fail 之后显示警告。
实现:(最好为所有测试文件创建一个基类):
测试用法
实际结果:
测试状态失败 -
红色测试通过并且出现警告,您将获得“不确定 - 黄色”状态。
Here is my hack on how to have warnings with nunit ( i know this question was about mstest, but this should work too). As always, I am interested in any improvements. This method is working for me.
Background: I have code which checks the tests themselves for correct comments and has logic to detect if someone has copied and pasted another test without changing comments. These are warnings I want to be shown to the developer without normal Assert.Inconclusive blocking the actual test from running. Some are focused on the test and the cleanup refactorings phase is to remove the warnings.
Mission: to have warnings after all other asserts are run. This means even showing the warnings after Assert.Fail that normally occur in tests during development.
Implementation: (best to create a base class for all test files):
Testing Usage
Actual Result:
Status of test is failed - RED
If the test passed and there was a warning, you will then get the status of Inconclusive - YELLOW.