Background
I'd like to auto test the Windows Form classes in my project. I'd like to conduct tests like "If Button F5
was clicked, has functionality xyz been executed?".
In order to do that I need to trigger mouse-click or keyboard events.
Environment
- Gui: Windows Forms
- Test framework: MSTests
- Test style: I don't tests an independent exe file
Question
How can I trigger mouse-click or keyboard events on a control?
+α: How to trigger any arbitrary event on an arbitrary control?
Concrete example
I have a GridDataView
in my productive form. In my test I run view.Row (0).selected = True
to select the first row. Now I'd like to trigger a doubleclick event and an Keys.Enter
Key event to simulate these user interactions.
What I've tried so far
view.PerformDoubleClick()
view.DoubleClick (Nothing,Nothing)
view.OnDoubleClick (Nothing)
RaiseEvent DoubleClick (Nothing,Nothing)
RaiseEvent view.DoubleClick (Nothing,Nothing)
None of these methods worked; some don't even compile
This Microsoft article indicates, that it might be impossible to accomplish, what I'm trying
An event can be raised only from the declaration space in which it is declared. Therefore, a class cannot raise events from any other class, even one from which it is derived.