Silverlight Unit Test Framework

來源:互聯網
上載者:User

微軟在08年的時候推出了一個Silverlight的單元測試架構,該架構在Mix 08的時候與Silverlight controls同時推出的,微軟工程師Jeff Wilcox一直參與維護該單元測試架構。
Scott Gu對這個架構的介紹
Jeff Wilcox提供的視頻介紹
該架構的原始碼已經包括在Silverlight controls中,有興趣的可以參考,在該架構的msdn代碼首頁, 可以找到最新的二進位檔案和相關教程及連結。

下面簡單說明如何使用這個單元測試架構。

首先我們要從這裡下載最新的單于測試架構的dll。
然後我們開啟vs2008建立一個silverlight application,用於運行單元測試,我們把這個工程命名為UnitTest。

把下載的架構dll解壓到項目工程目錄裡(我建立了一個ref目錄),然後右鍵點擊References添加剛才解壓的2個dll,Microsoft.Silverlight.Testing.dll和Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll。

因為架構可以產生測試頁面,所以我們把項目裡的page.xaml和page.xaml.cs刪除,然後開啟app.xaml.cs,在頁面裡添加對Microsoft.Silverlight.Testing的引用,並且把RootVisual修改為UnitTestSystem.CreateTestPage();

view plaincopy to clipboardprint?
  1. #using Microsoft.Silverlight.Testing;  
#using Microsoft.Silverlight.Testing;
view plaincopy to clipboardprint?
  1. private void Application_Startup(object sender, StartupEventArgs e)   
  2.        {   
  3.   
  4.            this.RootVisual = UnitTestSystem.CreateTestPage();   
  5.        }  
 private void Application_Startup(object sender, StartupEventArgs e)        {            this.RootVisual = UnitTestSystem.CreateTestPage();        }

然後我們在工程裡添加一個class,在class裡引用Microsoft.VisualStudio.TestTools.UnitTesting,然後加入一個TestMethod,代碼如下:

view plaincopy to clipboardprint?
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;   
  2.   
  3. namespace UnitTest   
  4. {   
  5.     [TestClass]   
  6.     public class TestGame   
  7.     {   
  8.         [TestMethod]   
  9.         public void TestDispose()   
  10.         {   
  11.             Assert.IsTrue(true);   
  12.         }   
  13.     }   
  14. }  
using Microsoft.VisualStudio.TestTools.UnitTesting;namespace UnitTest{    [TestClass]    public class TestGame    {        [TestMethod]        public void TestDispose()        {            Assert.IsTrue(true);        }    }}

按F5運行工程,看看輸出結果,是不是很方便?

當然你也可以用這個架構進行Silverlight UI的單元測試工作,具體可以看Jeff的這篇文章。

轉載請註明來自ET瓦力Silverlight技術中文部落格

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.