1 / 31

Developing Testable Silverlight Applications

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?.

sinead
Download Presentation

Developing Testable Silverlight Applications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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

  3. What Is Testability? • An application’s testability is the inherent ability to efficiently isolate, evaluate, and communicate the application’s quality.

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

  5. 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

  6. 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

  7. 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

  8. Model-View-ViewModel (M-V-VM)Defining the pattern for testability • Maintains View state • Exposes data points • Does not contain UI ViewModel Model View

  9. Model-View-ViewModel (M-V-VM)Defining the pattern for testability • Simply data points ViewModel Model View

  10. 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

  11. 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; } }

  12. Inversion of ControlMost complete solution • Dependency injection (DI) containers • Register dependencies at application startup • Resolve dependencies when needed

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

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  19. 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

  20. 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

  21. Testing the Tiers with RIA Services and Silverlight 4 demo

  22. 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

  23. 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

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

  25. 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

  26. 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

  27. 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

  28. YOUR FEEDBACK IS IMPORTANT TO US! Please fill out session evaluation forms online at MicrosoftPDC.com

  29. 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….

More Related