by, ben dewey senior software developer tallan, inc. ben@bendewey.com

Post on 20-Dec-2015

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Unit Testing your Silverlight Applications Using the Silverlight

Unit Testing FrameworkBy, Ben Dewey

Senior Software DeveloperTallan, Inc.

ben@bendewey.comhttp://bendewey.com/blog

http://twitter.com/bendewey

AssumptionsBasic knowledge of

SilverlightUnit Testing

Nice to have knowledge ofMSTest

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

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

Original Unit Testing Framework

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

Setting up the Test HarnessAdd Project

Silverlight Unit Testing Applications

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();}

Context

Demo

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();        }    }

Links

http://silverlight.codeplex.com

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

Microsoft Design Toolbox

http://microsoft.com/design/toolbox

Thank YouBy, Ben Dewey

ben@bendewey.comhttp://bendewey.com/blog

http://twitter.com/bendewey

top related