Silverlight2 Unit Testing Slides
Upcoming SlideShare
Loading in...5

Silverlight2 Unit Testing Slides






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Silverlight2 Unit Testing Slides Silverlight2 Unit Testing Slides Presentation Transcript

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