31
Developing Testable Silverlight Applications Keith Jones Senior SDET - Silverlight Microsoft Corporation CL32

Developing Testable Silverlight Applications

  • Upload
    sinead

  • View
    29

  • Download
    1

Embed Size (px)

DESCRIPTION

CL32. Developing Testable Silverlight Applications. Keith Jones Senior SDET - Silverlight Microsoft Corporation. When Testability Matters. Your customer’s requirements just changed Your management wants a demo at 5:00 It’s the end game and your schedule is tight. What Is Testability?. - PowerPoint PPT Presentation

Citation preview

Page 1: Developing Testable Silverlight Applications

Developing Testable Silverlight Applications

Keith JonesSenior SDET - SilverlightMicrosoft Corporation

CL32

Page 2: Developing Testable Silverlight Applications

When Testability Matters> Your customer’s requirements just

changed> Your management wants a demo at

5:00> It’s the end game and your schedule

is tight

Page 3: Developing Testable Silverlight Applications

What Is Testability?> An application’s testability is the

inherent ability to efficiently isolate, evaluate, and communicate the application’s quality.

Page 4: Developing Testable Silverlight Applications

Effects of Poor Testability on Tests> Complicated setup/teardown> Too many points for failure> Too many unrelated verifications> High maintenance costs> Slow

Page 5: Developing Testable Silverlight Applications

Agenda> Separating concerns with M-V-VM> Decoupling with inversion of control> Using the Silverlight Unit Test

Framework> Leveraging .NET RIA Services> Testing the View

Page 6: Developing Testable Silverlight Applications

Model-View-ViewModel (M-V-VM)Background> Design pattern optimized for separation of

concerns on WPF and Silverlight> Heavily leverages data-binding> Encourages designers to own user

experience

Page 7: Developing Testable Silverlight Applications

Model-View-ViewModel (M-V-VM)Defining the pattern for testability

> Contains the controls and behaviors that make up the user interface

> Defined declaratively (if possible)> Adding code-behind is ok, but keep it thin

View ViewModel Model

Page 8: Developing Testable Silverlight Applications

Model-View-ViewModel (M-V-VM)Defining the pattern for testability

> Maintains View state> Exposes data points> Does not contain UI

View ViewModel Model

Page 9: Developing Testable Silverlight Applications

Model-View-ViewModel (M-V-VM)Defining the pattern for testability

> Simply data points

View ViewModel Model

Page 10: Developing Testable Silverlight Applications

Agenda> Separating concerns with M-V-VM> Decoupling with inversion of

control> Using the Silverlight Unit Test

Framework> Leveraging .NET RIA Services> Testing the View

Page 11: Developing Testable Silverlight Applications

Inversion of ControlSimplest solution> Dependency inversion with

parameterized constructors and interfaces

> Before public class Foo { Bar _bar; public Foo() { this._bar = new Bar(); } }

> After public class Foo { IBar _bar; public Foo(IBar barDependency) { this._bar = barDependency; } }

Page 12: Developing Testable Silverlight Applications

Inversion of ControlMost complete solution> Dependency injection (DI) containers> Register dependencies at application

startup> Resolve dependencies when needed

Page 13: Developing Testable Silverlight Applications

Inversion of Control +Model-View-ViewModel +Silverlight 4 = Better Testability

demo

Page 14: Developing Testable Silverlight Applications

Agenda> Separating concerns with M-V-VM> Decoupling with inversion of control> Using the Silverlight Unit Test

Framework> Leveraging .NET RIA Services> Testing the View

Page 15: Developing Testable Silverlight Applications

Silverlight Unit Test Framework Basics> Ships with the Silverlight Toolkit> API’s are nearly identical to VS unit

tests> Has some Silverlight specific features

> Tags> Asynchronous execution

Page 16: Developing Testable Silverlight Applications

Silverlight Unit Test FrameworkAsynchronous testing > Test execution is all on the UI thread> So are several crucial Silverlight operations> [Asynchronous] enables testing those

scenarios> Asynchronous tests are slow

Page 17: Developing Testable Silverlight Applications

Agenda> Separating concerns with M-V-VM> Decoupling with inversion of control> Using the Silverlight Unit Test

Framework> Leveraging .NET RIA Services> Testing the View

Page 18: Developing Testable Silverlight Applications

Intro to .NET RIA Services> Mission: Make n-tier RIA development as

easy as two-tier client app development> Prescriptive pattern for business logic on the

middle-tier: query and unit of work> RIA Services creates corresponding types for

your client app to use and handles the communication between the two tiers

> Write validation code once and have it applied on both the client and middle-tier layers

> Tooling to bring together web and Silverlight projects

Page 19: Developing Testable Silverlight Applications

Mid Tier

N-Tier Application with .NET RIA Services

> A domain model is a subset of the data from the store plus user types and business logic to solve a specific domain problem

Client DB

Domain Model

AppLogi

c

Data Bindable Domain Contexts

and Entities

DataClient and DataService

DataAppUI

Data Binding and Command

Binding

Code Generation

Page 20: Developing Testable Silverlight Applications

N-Tier Application with .NET RIA ServicesTesting strategy Mid TierClient DB

Domain Model

AppLogi

c

Data Bindable Domain Contexts

and Entities

DataClient and DataService

DataAppUI

Data Binding and Command

Binding

View ViewModel/Model Middle Tier Business Logic

Page 21: Developing Testable Silverlight Applications

Testing the Tiers with RIA Services and Silverlight 4

demo

Page 22: Developing Testable Silverlight Applications

Agenda> Separating concerns with M-V-VM> Decoupling with inversion of control> Using the Silverlight Unit Test

Framework> Leveraging .NET RIA Services> Testing the View

Page 23: Developing Testable Silverlight Applications

Testing the View Trains of thought> Use UIAutomation accessibility hooks to

programmatically control the UI> Send actual mouse clicks and keyboard

presses to simulate actual user actions> Register a browser plug-in to bridge desktop

testing capabilities with the ability to access internal application information

Page 24: Developing Testable Silverlight Applications

What’s Left To Test?The dirty work> End to end> Globalization> Security> Performance> Stress

Page 25: Developing Testable Silverlight Applications

Show off what you learned> Use Inversion of Control and M-V-VM

with Silverlight 4> Make use of RIA Services for your n-

tier applications

Page 26: Developing Testable Silverlight Applications

Resources> Relevant talks

> Building LOB Applications with SL4 [CL19]> Building Amazing Business Applications with Microsoft

Silverlight and Microsoft .NET RIA Services [CL21]> Mastering Microsoft .NET RIA Services [CL07]> Advanced Topics for Building Large-Scale Applications with

Microsoft Silverlight [CL22]> Links

> My Blog – http://blogs.msdn.com/keithjones/ > Silverlight Toolkit - http://www.codeplex.com/Silverlight > Bing – Keywords: Silverlight, MVVM, ViewModel, RIA

Services

Page 27: Developing Testable Silverlight Applications

Inversion of ControlUnity vs. MEF

Unity> .NET and Silverlight> Default DI container

mechanism for Composite Application Guidance (a.k.a. Prism)

> Supports many DI patterns and discovery and wireup mechanisms

MEF> .NET 4.0 and Silverlight> .NET 4.0 version is used

for new VS 10 extensibility

> Strength lies in extensibility, dynamic discovery, and auto-wireup

> Discovery through attributes limits use with existing assets

Page 28: Developing Testable Silverlight Applications

YOUR FEEDBACK IS IMPORTANT TO US! Please fill out session evaluation

forms online atMicrosoftPDC.com

Page 29: Developing Testable Silverlight Applications

Learn More On Channel 9> Expand your PDC experience through

Channel 9

> Explore videos, hands-on labs, sample code and demos through the new Channel 9 training courses

channel9.msdn.com/learnBuilt by Developers for Developers….

Page 30: Developing Testable Silverlight Applications

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 31: Developing Testable Silverlight Applications