JSWork
JSWork

Reputation: 1025

Test Driven Development - WPF

I'd like to shift my code to a more test driven development model, but am unsure the best way to do this for the presentation layer.

Other layers behave like a black box where you can give input and expect output.

The presentation layer is not so simple. Are there any programs, guides, or practices to help with test driven xaml development.

Upvotes: 3

Views: 4649

Answers (2)

Gishu
Gishu

Reputation: 136593

Well I cannot refrain from posting an answer. The approach shown in the accepted answer is a maintenance-trap to say the least.

Move your GUI development to the MVP / MVVM model. WPF is MVVM friendly. Make thin GUIs (with minimal code/logic) that delegate/sync with a Presenter class. This means that you can write unit tests against the presenter and test a significant portion of your code without the UI. Write only a handful of UI tests and perform the majority of your functional testing using the presenter class.

Writing UI tests isn't the answer (for non-trivial GUIs) because they are

  • unreadable. UI tests degenerate into long arcane scripts that are manipulating UI elements. It is difficult to see what is being tested since the how obscures it. If you can't read it, it'll take you longer to fix it once it breaks.
  • slow. You'd be running fewer tests per unit of time.
  • brittle. A Gui change can break a number of your GUI-coupled tests even though the functionality isn't. More test maintenance.
  • unstable. You'd have to invest some amount of time in stabilizing the tests so that they run reliably each time. Introducing delays or polling for some things to show up.

Upvotes: 13

N_A
N_A

Reputation: 19897

Here is something from microsoft on the topic. For further information, see the link in the comments. http://msdn.microsoft.com/en-us/magazine/dd483216.aspx

Upvotes: 4

Related Questions