How to go about implementing Specflow with WPF app using MVVM

We have an app which is developed in wpf + DevExpress using MVVM pattern. We need to implement Specflow with MStest on viewmodel level.

Have anyone tried this? Any pointers? Is codedUI any good at viewmodel level?

Answers


I had two thoughts when I read that question.

First - think if you really need to automate everything through the UI. With an architecture like MVVM you have a great opportunity to hit the application beneath the UI and still get a lot out your test automation. For example write your step definitions against the ViewModels. Testing against the UI easily run the risk of creating brittle tests. The UI is the part of most application that changes very frequently. Tests hitting the UI need to cope with this somehow (more on this later).

Secondly, for the things that you need to automate against the UI, consider using White which is a nice object oriented abstraction above the UI Automation Library. I've used it extensively and like it.

With any automation be sure to create an abstraction over the actual automation, with the driver pattern for example. A simple way to do this is to create a screen/page object that have properties and methods to interact with the screen/page in question. Your step definitions then uses these wrapper objects.

Keep your step definitions thin and your wrapper objects fat. A bit like a controller in the MVC-pattern. More on this here

I hope this was helpful


Well I haven't tried it but I can't see anything wrong with it. By using specflow you create methods to do one thing say "The user presses the about button" and your code would be something like this

[Given(@"The user presses the about button")]
public void TheUserPressesTheAboutButton()
{ 
    this.UIMap.PressAboutButton();
}

You may have to fiddle around to create all the methods but it's not a big deal. There's a simple guide here. Something that could be a glitch is the naming and identification of the controls so that CUIT builder would be able to find them.


Yes. It works pretty good. The biggest challenge is really defining your sentence structure and Given/When/Then statements so they are consistent and re-usable. Otherwise you end up with Tags and 5-10 givens for a single method. Not really maintainable.

We used Specflow for unit testing MVVM as well as other business components. The Given statements would basically setup the mock data, then execute the test:

Given I have created a database context
And it contains the following Books
|ISBN   | Author  | Title  |
...

I also used specflow for Functional Testing (end to end) for automated testing via TFS. A database and server are deployed (with real or test data), then the functional test suite is executed against that server/database (creating data, modifying data, etc).


Need Your Help

Ajax changing php state with javascript button click

javascript php html ajax button

I am trying to display 9 last uploaded images through AJAX, but also be able to navigate through past uploaded images as well.

Extracting String from string which fit certain width

iphone objective-c ios

if i have String "Life is Good". now i need to extract some words from that string which fits on width 40. how can achieve this from objective C ?