automated unit testing in silverlight for windows phone 7

19
Automated Unit Testing with Silverlight for Windows Phone 7 Jacinto Limjap, Jr. Microsoft MVP for C# Senior Applications Developer, FBM e-Services

Upload: jacinto-limjap

Post on 10-May-2015

4.081 views

Category:

Technology


6 download

DESCRIPTION

A short overview on Test Driven Development and the MVVM Pattern, in the context of applying it in Windows Phone 7

TRANSCRIPT

Page 1: Automated Unit Testing in Silverlight for Windows Phone 7

Automated Unit Testing with Silverlight for Windows Phone 7

Jacinto Limjap, Jr.Microsoft MVP for C#

Senior Applications Developer, FBM e-Services

Page 2: Automated Unit Testing in Silverlight for Windows Phone 7

Agenda

• Automated unit testing and Test Driven Development

• MVVM – an overview• Putting it all together using Silverlight for

Windows Phone 7

Page 3: Automated Unit Testing in Silverlight for Windows Phone 7

Any mobile developers in the house?

What do you use in terms of frameworks/patterns/unit testing?

Page 4: Automated Unit Testing in Silverlight for Windows Phone 7

AUTOMATED UNIT TESTING & TDDAn introduction

Page 5: Automated Unit Testing in Silverlight for Windows Phone 7

What is Test Driven Development?

• Using unit tests to design software• Allows change in code without fear of

(inadvertently ) changing functionality• Produces loosely coupled objects and

methods with single responsibilities

Page 6: Automated Unit Testing in Silverlight for Windows Phone 7

What is Test Driven Development?

• Unit tests are just side effects: main point is DESIGN

• Write tests first, code later (?!)

Page 7: Automated Unit Testing in Silverlight for Windows Phone 7

What is Test Driven Development NOT?

• Substitute for QA testing• Necessarily means successful project• Silver bullet

Page 8: Automated Unit Testing in Silverlight for Windows Phone 7

TDD Mindset

Page 9: Automated Unit Testing in Silverlight for Windows Phone 7

Writing Tests

• Think about how you want to express your code and intentions

• Think about inputs, and intended output• Separate small, isolated areas of functionality

Page 10: Automated Unit Testing in Silverlight for Windows Phone 7

Issues

• Unit tests should come BEFORE code• Unit tests should NOT depend on presence or

absence or external dependencies (e.g., storage, database, internet connection)

• How to solve this: Mocks, stubs and fakes

Page 11: Automated Unit Testing in Silverlight for Windows Phone 7

Do we really have to do test first?

Page 12: Automated Unit Testing in Silverlight for Windows Phone 7

MVVMThe Model View ViewModel Pattern

Page 13: Automated Unit Testing in Silverlight for Windows Phone 7

Model-View-ViewModel

• Introduced in 2005 by John Gossman• Originally designed for Windows Presentation

Foundation (WPF) applications• Designed in response to attempts to use

Model-View-Controller (MVC) in WPF

Page 14: Automated Unit Testing in Silverlight for Windows Phone 7

Model-View-ViewModel

• Model – class or data representation of object you are using within your application

• View – the part of your application representing the user interface

• ViewModel – class or data representation of an object or combination of objects, as seen in the View

Page 15: Automated Unit Testing in Silverlight for Windows Phone 7

Model-View-ViewModel

View(XAML)

View(XAML)

View ModelView Model

ModelModel

Data BindingData Binding

Page 16: Automated Unit Testing in Silverlight for Windows Phone 7

So why is MVVM important?

Page 17: Automated Unit Testing in Silverlight for Windows Phone 7

DEMOUnit testing on Silverlight for Windows Phone 7

Page 18: Automated Unit Testing in Silverlight for Windows Phone 7

Discussion

• http://dotnet.kapenilattex.com• http://twitter.com/LaTtEX• http://facebook.com/LaTtEX

Page 19: Automated Unit Testing in Silverlight for Windows Phone 7

References• Introduction to Model/View/ViewModel pattern for building WPF apps http://

blogs.msdn.com/b/johngossman/archive/2005/10/08/478683.aspx• Silverlight Patterns: Model-View-ViewModel in Silverlight 2 apps http://

msdn.microsoft.com/en-us/magazine/dd458800.aspx• Model-View-ViewModel (MVVM) Explained http://

csharperimage.jeremylikness.com/2010/04/model-view-viewmodel-mvvm-explained.html• Introduction to Test Driven Development http://dotnet.kapenilattex.com/?p=201• Windows Phone 7 Tutorials http://compiledexperience.com/windows-phone-7• Updated Silverlight Unit Testing Framework bits for Windows Phone and Silverlight 3

http://www.jeff.wilcox.name/2010/05/sl3-utf-bits/• Steps to run the Windows Phone 7 Unit Test Framework successfully http://

codingsolutions.blogspot.com/2010/03/steps-to-run-windows-phone-7-unit-test.html• TDD Kata for Windows Phone 7

http://github.com/dgadd/TDD_Kata_For_MVVM_on_Win_Phone_7• Migrating Apps from Windows Phone April CTP Refresh to Beta Build

http://blogs.msdn.com/b/jaimer/archive/2010/06/28/migrating-apps-from-windows-phone-ctps-to-the-beta-build.aspx?wa=wsignin1.0