Testing WinForms/CompositeUI GUI with SpecFlow, White, Spring and MS Test
Asked Answered
G

1

6

I've got a C# desktop application (CompositUI/WinForms). This application connects to a webservice using SmartClient. My task is to introduce (retrofit) tests to this application, using SpecFlow and White frameworks. In order to just test the GUI, I need to mock the webservice calls. The class that connects to it is being inject via Spring.net. My task is to test the application being able to mock the webservice call during tests, that means, my test code needs to be in control of what my mock will do. The problem: method that starts the GUI is simply not returning control to the thread that has invoked it. In result, we cannot control the GUI and mocks.

So questions I have at this point are:

  • is it doable (and if so - how to do it) to start GUI in separate thread and have control back to the test thread?

  • what would be other possibilities of running GUI tests, that would allow me to have control over injected?

Gareth answered 16/3, 2012 at 14:55 Comment(0)
R
-1

Essential to test .net UI your going to have to use a MVVM toolset or create one so you can configure your solution to test the methods used by the UI. There are a number of frameworks for .net that support this can be found on Wikipedia.

The basics underlying all the MVVM UI tests are a DI/IOC framework, which you will need to pick as well.

Essentially you create a ViewModel class that you can test. For an example of unit testing with WPF - http://www.markermetro.com/2010/07/technical/mvvm-light-and-unit-testing-example/

Now there a few gotchas to think about. Firstly the .NET WinForms is not going to have major changes by M$ (THANKS A BUNCH!) and XAML/WPF has no upgrade path. MS$ have indicated that developers should start using the WPF UI designers for desktop projects moving forward. The number of MVVM frameworks that support WinForms is limited, so you may have to roll your own via DI, but have a look at the following StackOverflow discussion on the topic.

Secondly the .NET Forms to WPF to Windows Phone to Web UI to Metro UI implementation issues. Microsoft's P&P team created Prism for xaml/WPF has some Dependancy Injection anti patterns (Service Locator is BAD) according to Mark Seemann and his Dependency Injection in .NET book. Prism hasn't been upgraded to Metro and re-architected, confusing adopters and making it partially redundant. Essentially my point is, getting a framework to allow your application UI to move forward is going to be difficult.

Rompish answered 4/1, 2014 at 8:4 Comment(3)
This doesn't answer the question. He's not talking about unit testing presentation logic, he actually wants to have the test click the buttons and type into the text boxes. How you build the ui (mvvm, MVP, code behind) is irrelevant to that kind of testing.Elimination
Also winforms is supported, but its not going to have major changes. Wpf would be the preferred way to build new desktop apps (those aren't going away) and xaml/winrt or win/js apps for Windows store apps.Elimination
@Elimination modified reply to clarify technology.Rompish

© 2022 - 2024 — McMap. All rights reserved.