By, Ben Dewey Senior Software Developer Tallan, Inc. [email protected] .

14
Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework By, Ben Dewey Senior Software Developer Tallan, Inc. [email protected] http ://bendewey.com/blog http://twitter.com/bendewey
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    215
  • download

    0

Transcript of By, Ben Dewey Senior Software Developer Tallan, Inc. [email protected] .

Page 1: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

Unit Testing your Silverlight Applications Using the Silverlight

Unit Testing FrameworkBy, Ben Dewey

Senior Software DeveloperTallan, Inc.

[email protected]://bendewey.com/blog

http://twitter.com/bendewey

Page 2: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

AssumptionsBasic knowledge of

SilverlightUnit Testing

Nice to have knowledge ofMSTest

Page 3: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

OverviewWhat is Testing/TDDSetting up the Silverlight Unit Testing Test HarnessBasic Unit TestAsynchronous Unit TestsQuestions

Page 4: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

PrefaceUnit Testing (MSTest)

[TestMethod]public void Can_AddNumbers(){ // Arrange var calculator = new Calculator();

// Act var result = calculator.Add(1, 2);

// Assert Assert.AreEqual(3, result);}

Test Driven Design (TDD)Testing first and allowing your tests/requirements to drive

your design

Page 5: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

Original Unit Testing Framework

Page 6: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

April 2010 Silverlight Toolkithttp://silverlight.codeplex.com

Page 7: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

Setting up the Test HarnessAdd Project

Silverlight Unit Testing Applications

Page 8: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

Setting up the Test HarnessAdd References

Microsoft.Silverlight.TestingMicrosoft.VisualStudio.QualityTools.UnitTesting.Silverlight

Modify App.xaml.cs

private void Application_Startup(object sender, StartupEventArgs e){    RootVisual = UnitTestSystem.CreateTestPage();}

Page 9: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

Context

Page 10: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

Demo

Page 11: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

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;

            EnqueueDelay(500);            EnqueueCallback(() =>            {                // Act                controller.ShowStartScreen  = false;             // Assert                Assert.AreEqual(Visibility.Collapsed, startWindow.Visibility);                Assert.AreEqual(Visibility.Collapsed, endWindow.Visibility);            });            EnqueueDelay(500);

            EnqueueTestComplete();        }    }

Page 12: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

Links

http://silverlight.codeplex.com

http://www.jeff.wilcox.name/Jeff Wilcox – Creator of SUT

Page 13: By, Ben Dewey Senior Software Developer Tallan, Inc. ben@bendewey.com  .

Microsoft Design Toolbox

http://microsoft.com/design/toolbox