test and profile your windows phone 8 app
DESCRIPTION
In this presentation i will give you a deep overview about Windows Phone 8 testing tool and how to profile and monitor your application performance.TRANSCRIPT
![Page 1: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/1.jpg)
WPReborn 2013
Michele CapraSoftware Engineer @ OrangeCode
___________________________________________________
Test and profile your application
@dnlombardia#wpreborn
![Page 2: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/2.jpg)
What we’re going to see:
• Testing in WP7
• Testing tools for WP8
• Profiling tools
![Page 3: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/3.jpg)
Who am I• Freelance Developer
• C#, Asp.net mvc, WPF , Windows Phone 7 – 8
• Python, Django
• Blog: orangecode.it/blog
![Page 4: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/4.jpg)
Where we were
Unit / Integration test : - Microsoft Test - Nunit for Windows Phone 7
Mocking framework:- Moq 3.1 for Silverlight
![Page 5: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/5.jpg)
Test runner for Windows Phone 7
• Nunit runner
• Resharper
• Test Driven.net
![Page 6: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/6.jpg)
Solution structure in Windows Phone 7WP7 App
WP7 Class Library
TestSuite
View and ViewModel
![Page 7: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/7.jpg)
Testing in Windows Phone 8
- Windows Phone 8 new feature
- Asyncronous programming style
- Need of an emulator to run the code- No test runner can be used directly in Visual Studio
![Page 8: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/8.jpg)
Windows Phone Toolkit Test Framework
• Part of the Windows Phone Toolkit
• Provides an easy way to integrate unit tests for your Windows Phone apps
![Page 9: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/9.jpg)
Windows Phone Toolkit Test Framework
• Test suites are no longer Class Libraries but Applications
• No more automated run
• Can manage asycnronous code
![Page 10: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/10.jpg)
How to setup WP8 testing tools• Reference via nuget: Windows Phone Toolkit
Test Framework• On your MainPage costructor: public partial class MainPage : PhoneApplicationPage { public MainPage() { InitializeComponent(); Content = UnitTestSystem.CreateTestPage(); } }
![Page 11: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/11.jpg)
How to setup WP8 testing tools
![Page 12: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/12.jpg)
Test example scenario
• App loads products informations from db and shows it
• SQLite as db engine
• ModelView-View-Model pattern
![Page 13: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/13.jpg)
Solution structure
![Page 14: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/14.jpg)
First test [TestClass] public class MainViewModelFixture { private MainViewModel _viewModel; private Mock<IDbService> _service; public MainViewModelFixture() { _service= new Mock<IDbService>(); _viewModel= new MainViewModel(_service.Object); } [TestMethod] public void Initialize_Should_LoadDataFromDb() { _viewModel.Initialize(); _service.Verify(p=>p.LoadProducts()); } }
![Page 15: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/15.jpg)
Run test
![Page 16: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/16.jpg)
Red to Greenusing Caliburn.Micro;using OrangeCode.Wpreborn.SQLIteApp.Services;namespace OrangeCode.Wpreborn.SQLIteApp.ViewModels{ public class MainViewModel :PropertyChangedBase { private readonly IDbService _service;
public MainViewModel(IDbService service) { _service = service; } public void Initialize() { _service.LoadProducts(); } }}
![Page 17: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/17.jpg)
Red to Green
![Page 18: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/18.jpg)
Second test [TestMethod] public void Initialize_Should_ShowData() { _service.Setup(p => p.LoadProducts()).Returns(
new List<Product>{new Product {Name = "Product 1", Serial =
"123456"} } );
_viewModel.Initialize();
Assert.AreEqual(_viewModel.Products.Count,1); Assert.AreEqual(_viewModel.Products[0].Serial,"123456"); }
![Page 19: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/19.jpg)
Second test public class MainViewModel :PropertyChangedBase { private readonly IDbService _service; public IList<Product> Products { get; set; }
public MainViewModel(IDbService service) { _service = service; } public void Initialize() { Products=_service.LoadProducts(); } }
![Page 20: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/20.jpg)
Second test
![Page 21: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/21.jpg)
Asynchronous testingHow to test this?
public interface IDbServiceAsync{ Task<IList<Product>> LoadProductsAsync(); } public class DbServiceAsync :IDbServiceAsync{ private readonly SQLiteAsyncConnection _context; public DbService(SQLiteAsyncConnection context) { _context = context; } public async Task<IList<Product>> LoadProductsAsync() { return await _context.Table<Product>().ToListAsync(); } }
![Page 22: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/22.jpg)
Asynchronous testingThat’s the easy way to test it..
private async void PrepareDb() { SQLiteAsyncConnection connection = new SQLiteAsyncConnection("TestDb.sqlite”); await connection.DropTableAsync<Product>(); await connection.CreateTableAsync<Product>(); await connection.InsertAsync(new Product { Name = "Product 1", Serial = "123456" }); } [TestMethod] public async void LoadProductsAsync_Should_Load_Data_FromDb() { await PrepareDb(); var data= await _service.LoadProductsAsync(); Assert.AreEqual(data.Count,1); }
![Page 23: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/23.jpg)
Let’s run the test suite
![Page 24: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/24.jpg)
FeelingsWhat I like: - Test real code- Async / await runner support
What I dislike: - No automated runner- No class library support
![Page 25: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/25.jpg)
Profiling appVisual Studio 2012 provides the Windows Phone Application Analysis tool.
Main feature:• App Monitoring: you can evaluate the most important
behaviors of your app that contribute to a good user experience, such as start time and responsiveness.
• Profiling: you can evaluate either execution-related or memory-usage aspects of your app.
![Page 26: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/26.jpg)
Phone application anaysis tool
![Page 27: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/27.jpg)
Test app
![Page 28: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/28.jpg)
Running dei profiling
![Page 29: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/29.jpg)
Phone application report
![Page 30: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/30.jpg)
Report Details
![Page 31: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/31.jpg)
Memory good practice
- Implement IDisposable in ViewModel
- Unload all event listener
- Consider using VirtualizingStackPanel instead of StackPanel
![Page 32: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/32.jpg)
Quick recap
- Windows Phone Toolkit Test Framework
- Windows Phone Application Analysis
![Page 33: Test and profile your Windows Phone 8 App](https://reader034.vdocuments.mx/reader034/viewer/2022042601/5553b5a2b4c905d9448b4d1d/html5/thumbnails/33.jpg)
That’s all folks- GitHub repos:
- Testing : https://github.com/piccoloaiutante/WP8TestingExample
- Profiling: https://github.com/piccoloaiutante/WP8ProfilingExample
- Contact:
Email : [email protected] Blog: www.orangecode.it/blog
Twitter: @piccoloaiutante GitHub: github.com/piccoloaiutante