Saturday, September 13, 2014

WPF Automation

I've been working through the 70-511 test preparation book, which is a terrible book but the only one focused on this certificate. I got to the section on automation and I just don't get it. The idea is to build unit tests for applications that replicate the user performing a well defined series of tasks.

Here is an example of using automation to simulate a button click pulled straight from the book...

aWindow = New MainWindow aWindow.Show() Dim BAutomationPeer As New Automation.Peers.ButtonAutomationPeer(aWindow.Button1) Dim InvProvider As IInvokeProvider InvProvider = BAutomationPeer.GetPattern(PatternInterface.Invoke) InvProvider.Invoke()

Four lines of code to simulate a click? Why is that better than...

aWindow = New MainWindow aWindow.Show() aWindow.Button1.RaiseEvent(New RoutedEventArgs(Button.ClickEvent, Button1))

I'm pretty sure I can simulate any event I want to with the RaiseEvent method.

Also the book example creates the window to be tested from the testing window. This has got to be a bad pattern. Surely the testing window should find an already instantiated window and obtain a reference to it. Perhaps something like...

Dim aWindow as MainWindow = Application.Current.MainWindow aWindow.Button1.RaiseEvent(New RoutedEventArgs(Button.ClickEvent, Button1))
I rather like the idea of having an icon on a page that has test scripts (hidden to regular users) that opens a page of test scripts and passes the page as a reference to the test page. Then the tester could easily perform standard tests. The scripts should also include tests of the results too. For example a script that tests the creation of a balanced purchase order would test the net amount is zero after the purchase order is entered.

What is it about Automation I am missing? The book doesn't explain.

No comments:

Post a Comment