问题
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