Display Windows forms inside unit test methods

I just opened unit test projects in Visual Studio .NET and use testing methods to create examples of global code that I developed.

Some global methods include displaying reusable dialog boxes, such as a date picker and input field. The problem is that sometimes the forms will be displayed, and sometimes they will not.

I thought that this was due to modality, because I have a report preview form that can be shown modally or unfashionably. When I show that is non-modal, it is not displayed. When I show it modally, it happens.

Trying my input window never works:

string input = "";
using (InputBox box = new InputBox(Title, Prompt, Default))
{
    DialogResult result = box.ShowDialog();
    input = box.txtInput.Text.Trim();
}
return input;

Execution stops at the line "box.ShowDialog ()", and at that moment I can check the window and see that its size, location and visibility are configured correctly, but I do not see this form. I need to cancel the test to stop everything.

Can anyone help? I would like to use the unit testing project to act as a playground and demonstrate existing code, but it seems very limited if I cannot display certain forms. I understand that this is not really what unit testing is designed for, but I was hoping I could create a fun little sandbox in such a way as to help my developers speed up.

Thanks for any help in advance!

+4
source share
1

- ( ) : ShowInTaskbar.

true, unit test. , . , , , , unit test:

  • Windows Form .
  • ShowInTaskbar FALSE.
  • (.. ShowDialog()).

, .

+10

Source: https://habr.com/ru/post/1624185/


All Articles