我有什么做的,这样的断言不会阻止自动测试了吗? [英] What do I have to do so that assertions won't block automated tests anymore?

查看:144
本文介绍了我有什么做的,这样的断言不会阻止自动测试了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们运行自动化 NUnit的使用上运行一些服务器上大多是无人值守的多个虚拟机哈德森/詹金斯我们的C#项目的测试。测试涉及开始交换数据,其中之一是NUnit的本身,由单位测试中创建的其他几个进程。

We run automated NUnit tests on our C# projects using hudson/jenkins on several virtual machines which run mostly unattended on some server. The tests involve starting several processes that exchange data, one of which is NUnit itself, the others created by the unit test.

有时,在一些开发商的检查触发之一的 断言 Debug.Assert的()) 。这就会弹出一个消息框,要求用户做什么。通常是那些发生在由单元测试中创建的外部过程之一。他们将 阻止这一进程,而其他进程放弃,因为他们无法沟通。然而,由于该系统的性质, 接下来的测试将全部失效,也只要一个进程被阻止等待有人点击即可该消息框。

Sometimes, one of the developer checks in something that triggers an assertion (Debug.Assert()). This then pops up a message box, asking the user what to do. Usually those happen in one of the "external" processes created by the unit tests. They will block that process while the other processes give up, because they can't communicate. However, due to the nature of the system, the next tests will all fail, too, as long as that one process is blocked waiting for someone to click away that message box.

我已经告诉你可以改变设置的.NET程序,以便断言不会弹出一个消息框。理想情况下,这个过程只会写些东西到标准输出或标准错误,詹金斯记录。

I've been told that you can change the settings for a .NET program so that an assertion won't pop up a message box. Ideally, the process would just write something to stdout or stderr, for Jenkins to record.

那么,我必须做的,关掉这些互动对话断言?

So what do I have to do to turn off those interactive assertion dialogs?

推荐答案

您需要实现System.Diagnostics.TraceListener不会弹出对话框上的失败(即你可以报告错误单元测试框架),并添加监听器,而不是默认的使用Listeners.Clear /添加在

You need to implement System.Diagnostics.TraceListener that will not pop up dialog on Fail (i.e. you can report error to unit test framework) and add this listener instead of default one by using Listeners.Clear/Add

public class MyListenerThatDoesNotShowDialogOnFail: System.Diagnostics.TraceListener
{....
    public override void Fail(string message, string detailMessage)
    {// do soemthing UnitTest friendly here
    }

}

System.Diagnostics.Debug.Listeners.Clear();
System.Diagnostics.Debug.Listeners.Add(new MyListenerThatDoesNotShowDialogOnFail());

这code应该是你的单元测试设置部分。这样,经常调试版本将显示对话框断言,但在运行单元测试它会做一些明智的测试(如Assert.Fail)。请注意,你应该考虑在测试的拆解方法恢复原来的听众。

This code should be in your Unit test setup portion. This way regular debug build will show assert dialogs, but while running Unit tests it will do something sensible for the test (like Assert.Fail). Note that you should consider restoring original listeners in test's teardown methods.

这篇关于我有什么做的,这样的断言不会阻止自动测试了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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