我需要从 NUnit 测试中创建一个 Windows 窗体 [英] I need to create a windows form from within a NUnit test

查看:63
本文介绍了我需要从 NUnit 测试中创建一个 Windows 窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个 NUnit 测试类来测试我的屏幕抓取工具.

I need to make a NUnit test class that tests my screen scraper.

1) 我想要一个 [SetUp] 方法来创建一个虚拟窗口,简单的窗口窗体,只有一个预定义的标题和一个背景图像.然后设置方法应该等待虚拟窗口的完全初始化,即等待虚拟窗体加载和显示背景图像并保持打开状态.

1) I would like to have a [SetUp] method that will create a dummy window, simple windows form with just a predefined title and a background image. Setup method then should wait for a full initialization of the dummy window, i.e. wait for the dummy form to load and display background image and keep it open.

2) 我将运行实际测试.

2) I will run the actual tests.

3) TearDown 方法将关闭虚拟窗口.

3) TearDown method will close the dummy window.

2) 和 3) 不是问题(我认为),但是我将如何执行 1),尤其是在保持虚拟窗口打开的同时将控制权传递给测试?

The 2) and 3) is not a problem (I think), but how would I do the 1), especially pass the control to the tests while keeping the dummy window open?

感谢您的任何建议.

推荐答案

只需创建一个表单并以无模式显示:

Just create a form and show it modeless:

[SetUp]
public void SetUp()
{
    m_myForm = new MyTestForm();
    m_myForm.Show(null);
}

[TearDown]
public void TearDown()
{
    m_myForm.Close();
    m_myForm.Dispose();
}
[Test]
//... some tests using the member variable

这篇关于我需要从 NUnit 测试中创建一个 Windows 窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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