By, Ben Dewey Senior Software Developer twentySix New York
Assumptions Basic knowledge of Silverlight Unit Testing Nice to have knowledge of MSTest
Overview What is Testing/TDD Setting up the Silverlight Unit Testing Test Harness Basic Unit Test Asynchronous Unit Tests Questions
Preface Unit Testing (MSTest) [TestMethod] public void Can_CreateCar() { // Arrange // Act var car = new Car(); // Assert Assert.IsNotNull(car); } Test Driven Design (TDD) Testing first and allowing your tests/requirements to drive your design
Original Unit Testing Framework
April 2010 Silverlight Toolkit
Context
Setting up the Test Harness Add Project Silverlight Unit Testing Applications
Setting up the Test Harness Add References Microsoft.Silverlight.Testing Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight Modify App.xaml.cs private void Application_Startup(object sender, StartupEventArgs e) { RootVisual = UnitTestSystem.CreateTestPage(); }
Asynchronous Unit Tests [TestClass] public class MainPageTests : SilverlightTest { [TestMethod, Asynchronous] public void Can_ShowHide_Windows() { // Arrange var controller = new GameController(); var mainPage = new MainPage(controller); this.TestPanel.Children.Add(mainPage); var startWindow = mainPage.FindName("StartWindow") as UIElement; var endWindow = mainPage.FindName("EndWindow") as UIElement; // Act // Assert EnqueueDelay(500); EnqueueCallback(() => { controller.ShowStartScreen = false; Assert.AreEqual(Visibility.Collapsed, startWindow.Visibility); Assert.AreEqual(Visibility.Collapsed, endWindow.Visibility); }); EnqueueDelay(500); EnqueueTestComplete(); } }
Links Jeff Wilcox – Creator of SUT
Microsoft Design Toolbox
By, Ben Dewey