I need to create a windows form from within a NUnit test

给你一囗甜甜゛ 提交于 2019-12-11 09:27:44

问题


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

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) I will run the actual tests.

3) TearDown method will close the dummy window.

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?

Thank you for any suggestion.


回答1:


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


来源:https://stackoverflow.com/questions/20022717/i-need-to-create-a-windows-form-from-within-a-nunit-test

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!