unit testing your silverlight applications using the silverlight unit testing framework

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

Upload: brenna

Post on 07-Jan-2016

45 views

Category:

Documents


3 download

DESCRIPTION

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. Assumptions. Basic knowledge of Silverlight Unit Testing - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

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: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

AssumptionsBasic knowledge of

SilverlightUnit Testing

Nice to have knowledge ofMSTest

Page 3: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

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

Page 4: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

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: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

Original Unit Testing Framework

Page 6: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

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

Page 7: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

Setting up the Test HarnessAdd Project

Silverlight Unit Testing Applications

Page 8: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

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: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

Context

Page 10: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

Demo

Page 11: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

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: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

Links

http://silverlight.codeplex.com

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

Page 13: Unit Testing your Silverlight Applications Using the Silverlight Unit Testing Framework

Microsoft Design Toolbox

http://microsoft.com/design/toolbox