Silverlight 2 Unit Testing Andre John Cruz MVP – Visual C#
Silverlight 2 <ul><li>Up-coming version of the Silverlight browser plugin with a mini version of the .NET Framework </li><...
Unit Testing <ul><li>Testing a specific portion or unit of a system </li></ul><ul><li>Can mean different things to differe...
Why Unit Test? <ul><li>Illustration: </li></ul>
Automated Unit Testing <ul><li>Usually with a tool like NUnit or MSTest </li></ul><ul><li>Silverlight presents new challen...
Silverlight 2 Testing Framework <ul><li>Adaptation of MSTest for Silverlight 2! </li></ul><ul><li>Browser-based unit test ...
How? <ul><li>Download Silverlight 2 beta 1, and Visual Studio 2008 Tools for Silverlight 2  </li></ul><ul><li>Silverlight ...
How? (part 2) <ul><li>Download the Silverlight test templates from  www.jeff.wilcox.name   </li></ul><ul><li>Ensure you ha...
Testing Framework <ul><li>Demo… </li></ul>
UI Testing Strategies <ul><li>Separation of concerns </li></ul><ul><ul><li>Don’t  put everything in code behind! </li></ul...
Examples <ul><li>Adding controls to the testing surface </li></ul><ul><li>Steps: </li></ul><ul><ul><li>Reference the app/c...
Examples <ul><li>Adding controls to the testing surface </li></ul><ul><li>Observations: </li></ul><ul><ul><li>Very helpful...
Examples <ul><li>Use of Model-View-Presenter pattern </li></ul><ul><ul><li>Very well-suited to view-centric frameworks suc...
Future Directions <ul><li>Silverlight 2, Testing Framework still in beta! </li></ul><ul><li>ScottGu mentioned… </li></ul><...
Thank You! <ul><li>Resources: </li></ul><ul><ul><li>ScottGu’s  wonderful  blog </li></ul></ul><ul><ul><li>http://www.jeff....
Upcoming SlideShare
Loading in...5
×

Silverlight2 Unit Testing Slides

978

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
978
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
24
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Silverlight2 Unit Testing Slides

  1. 1. Silverlight 2 Unit Testing Andre John Cruz MVP – Visual C#
  2. 2. Silverlight 2 <ul><li>Up-coming version of the Silverlight browser plugin with a mini version of the .NET Framework </li></ul><ul><li>Richer functionality than Silverlight 1.0 </li></ul><ul><li>Currently in beta </li></ul>
  3. 3. Unit Testing <ul><li>Testing a specific portion or unit of a system </li></ul><ul><li>Can mean different things to different people </li></ul><ul><ul><li>Unit = Small </li></ul></ul><ul><li>Automated unit testing: </li></ul><ul><ul><li>Test-first (TDD) </li></ul></ul><ul><ul><li>Test-after </li></ul></ul>
  4. 4. Why Unit Test? <ul><li>Illustration: </li></ul>
  5. 5. Automated Unit Testing <ul><li>Usually with a tool like NUnit or MSTest </li></ul><ul><li>Silverlight presents new challenges </li></ul><ul><ul><li>Silverlight 2 code runs in the browser (client) </li></ul></ul><ul><ul><li>UI testing is usually tricky </li></ul></ul>
  6. 6. Silverlight 2 Testing Framework <ul><li>Adaptation of MSTest for Silverlight 2! </li></ul><ul><li>Browser-based unit test runner </li></ul><ul><li>Capability to do UI testing </li></ul>
  7. 7. How? <ul><li>Download Silverlight 2 beta 1, and Visual Studio 2008 Tools for Silverlight 2 </li></ul><ul><li>Silverlight Testing Framework is included in the source code for Silverlight controls! </li></ul>
  8. 8. How? (part 2) <ul><li>Download the Silverlight test templates from www.jeff.wilcox.name </li></ul><ul><li>Ensure you have these DLLs </li></ul><ul><ul><li>Microsoft.Silverlight.Testing.dll </li></ul></ul><ul><ul><li>Microsoft.Silverlight.Testing.Framework.dll </li></ul></ul><ul><ul><li>Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll </li></ul></ul><ul><li>Mark your test class with the [TestClass] attribute and your test methods with [TestMethod] </li></ul>
  9. 9. Testing Framework <ul><li>Demo… </li></ul>
  10. 10. UI Testing Strategies <ul><li>Separation of concerns </li></ul><ul><ul><li>Don’t put everything in code behind! </li></ul></ul><ul><li>Small steps </li></ul><ul><li>You can make use of patterns such as Model-View-Presenter (MVP) </li></ul><ul><li>You can also add controls to the “testing surface” and assert against their properties </li></ul>
  11. 11. Examples <ul><li>Adding controls to the testing surface </li></ul><ul><li>Steps: </li></ul><ul><ul><li>Reference the app/control library in your test project </li></ul></ul><ul><ul><li>Derive your test class from the SilverlightTest class </li></ul></ul><ul><ul><li>Add your control to the TestSurface </li></ul></ul><ul><ul><li>Testing surface gets cleared before every test method run </li></ul></ul>
  12. 12. Examples <ul><li>Adding controls to the testing surface </li></ul><ul><li>Observations: </li></ul><ul><ul><li>Very helpful to use the [assembly:InternalsVisibleTo] attribute </li></ul></ul><ul><ul><li>Use “internal” methods instead of “private” for your event handlers so you can force-trigger them from your tests </li></ul></ul>
  13. 13. Examples <ul><li>Use of Model-View-Presenter pattern </li></ul><ul><ul><li>Very well-suited to view-centric frameworks such as Windows Forms and Silverlight/WPF </li></ul></ul><ul><ul><li>Allow you to test view logic without having a view ;) </li></ul></ul>
  14. 14. Future Directions <ul><li>Silverlight 2, Testing Framework still in beta! </li></ul><ul><li>ScottGu mentioned… </li></ul><ul><ul><li>Possible UI Automation API (e.g. simulate mouse/keyboard actions in code) </li></ul></ul><ul><ul><ul><li>This is more appropriately called “integration testing” </li></ul></ul></ul><ul><ul><li>Tighter integration into VS 2008 IDE </li></ul></ul>
  15. 15. Thank You! <ul><li>Resources: </li></ul><ul><ul><li>ScottGu’s wonderful blog </li></ul></ul><ul><ul><li>http://www.jeff.wilcox.name </li></ul></ul><ul><ul><li>http://silverlight.net </li></ul></ul><ul><li>Personal blog: </li></ul><ul><ul><li>http://devpinoy.org/blogs/cruizer </li></ul></ul><ul><ul><li>[email_address] </li></ul></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×