Silverlight2 Unit Testing Slides

  • 937 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
937
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
24
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Silverlight 2 Unit Testing Andre John Cruz MVP – Visual C#
  • 2. 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
  • 3. 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
  • 4. Why Unit Test?
    • Illustration:
  • 5. 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
  • 6. Silverlight 2 Testing Framework
    • Adaptation of MSTest for Silverlight 2!
    • Browser-based unit test runner
    • Capability to do UI testing
  • 7. 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!
  • 8. How? (part 2)
    • Download the Silverlight test templates from www.jeff.wilcox.name
    • 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]
  • 9. Testing Framework
    • Demo…
  • 10. 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
  • 11. 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
  • 12. 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
  • 13. 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 ;)
  • 14. 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
  • 15. Thank You!
    • Resources:
      • ScottGu’s wonderful blog
      • http://www.jeff.wilcox.name
      • http://silverlight.net
    • Personal blog:
      • http://devpinoy.org/blogs/cruizer
      • [email_address]