Displaying Windows Forms inside unit test methods

后端 未结 2 1795
一向
一向 2021-01-12 19:00

I just discovered unit test projects in Visual Studio .NET and am using test methods to set up examples of global code I have developed.

Some global methods involve

2条回答
  •  春和景丽
    2021-01-12 19:58

    I finally had some consistent success (and lack thereof) based on a single form property: ShowInTaskbar.

    When a form had that property set to true, such forms would NOT display from a unit test method. When that property is false, all forms display. So, here are the rules as far as I know them to make sure a form can display from a unit test:

    • The form should be created as a standard Windows Form item in the project.
    • The form should have its ShowInTaskbar property set to FALSE.
    • The form needs to be displayed modally (i.e. with ShowDialog()).

    This has let me display and test all of my utility forms like date selectors and login screens.

提交回复
热议问题