310 likes | 421 Views
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?.
E N D
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? • 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 ViewModel Model View
Model-View-ViewModel (M-V-VM)Defining the pattern for testability • Maintains View state • Exposes data points • Does not contain UI ViewModel Model View
Model-View-ViewModel (M-V-VM)Defining the pattern for testability • Simply data points ViewModel Model View
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 • After public class Foo { Bar _bar; public Foo() { this._bar = new Bar(); } } public class Foo { IBar_bar; public Foo(IBarbarDependency) { 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 FrameworkBasics • 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
N-Tier Application with .NET RIA Services Code Generation DB Mid Tier Client • A domain model is a subset of the data from the store plus user types and business logic to solve a specific domain problem Data App UI Data Bindable Domain Contexts and Entities App Logic Domain Model Data Binding and Command Binding DataClient and DataService
N-Tier Application with .NET RIA ServicesTesting strategy DB Mid Tier Client Data App UI Data Bindable Domain Contexts and Entities App Logic Domain Model Data Binding and Command Binding DataClient and DataService View ViewModel/Model Middle Tier Business Logic
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 ViewTrains 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 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 • .NET and Silverlight • Default DI container mechanism for Composite Application Guidance (a.k.a. Prism) • Supports many DI patterns and discovery and wireup mechanisms
YOUR FEEDBACK IS IMPORTANT TO US! Please fill out session evaluation forms online at MicrosoftPDC.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/learn Built by Developers for Developers….