Upload
sinead
View
27
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
Developing Testable Silverlight Applications
Keith JonesSenior SDET - SilverlightMicrosoft Corporation
CL32
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?> An application’s testability is the
inherent ability to efficiently isolate, evaluate, and communicate the application’s quality.
Effects of Poor Testability on Tests> Complicated setup/teardown> Too many points for failure> Too many unrelated verifications> High maintenance costs> Slow
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
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
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
Model-View-ViewModel (M-V-VM)Defining the pattern for testability
> Maintains View state> Exposes data points> Does not contain UI
View ViewModel Model
Model-View-ViewModel (M-V-VM)Defining the pattern for testability
> Simply data points
View ViewModel Model
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
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; } }
Inversion of ControlMost complete solution> Dependency injection (DI) containers> Register dependencies at application
startup> Resolve dependencies when needed
Inversion of Control +Model-View-ViewModel +Silverlight 4 = Better Testability
demo
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
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
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
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
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
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
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
Testing the Tiers with RIA Services and Silverlight 4
demo
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
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
What’s Left To Test?The dirty work> End to end> Globalization> Security> Performance> Stress
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
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
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
YOUR FEEDBACK IS IMPORTANT TO US! Please fill out session evaluation
forms online atMicrosoftPDC.com
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….
© 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.