CANTPRO
CANTPRO

Reputation: 79

Can I run unit tests as a Windows application?

Working on a school project. Just for fun, I'm wondering if I can drive events on a WinForm using SendKeys from a unit test. I have these requirements:

3. About Box
    a. Pressing the "F1" key on the keyboard shall display an about box window
    b. The about box window shall list the current software version and an email
         address for software support
    c. The about box window shall have a "OK" button
    d. Clicking the "OK" button shall close the about window

SendKeys works on the active assembly. The unit tests are in the namespace of the program, and the form. When I get the exception that the assembly isn't accepting messages when I try and use SendKeys in a unit test, that just means the application is running as a class library and not a Windows application, right? Is there a way to get the tests to execute as a Windows Application?

I'm guessing the best I can do is to create an instance of my form from the unit test and manually call the method handling the F1 key?

Upvotes: 0

Views: 672

Answers (1)

Daniel Mann
Daniel Mann

Reputation: 59018

That's not a unit test, that's a UI test. There are numerous UI testing frameworks out there (my preference being Microsoft's Coded UI).

A unit test tests a single method or class in isolation, which means it has no dependencies that are outside of your control. If you're testing your logic via the UI, that's not isolated at all.

Upvotes: 1

Related Questions