2013-02-13 78 views
1

所以,我也非常驚訝的是,「創建單元測試」是不是可以從上下文菜單時,右鍵單擊過的方法,而不是Visual Studio 2010中的Visual Studio 2012自動創建單元測試 - WP8應用

建議的解決方法是在VS2010中創建單元測試,然後將其導回到VS2012。

然後我發現這個職位http://dl.my/2013/enable-create-unit-tests-on-visual-studio-2012/ 這確實有效!

但是現在,在單擊方法上的「創建單元測試」後,生成的類只包含一個TestContext屬性,而沒有在嚮導中選擇的測試方法。

這是生成的類:

/// <summary> 
///This is a test class for XXXTest and is intended 
///to contain all XXXTest Unit Tests 
///</summary> 
[TestClass()] 
public class XXXTest 
{ 


    private TestContext testContextInstance; 

    /// <summary> 
    ///Gets or sets the test context which provides 
    ///information about and functionality for the current test run. 
    ///</summary> 
    public TestContext TestContext 
    { 
     get 
     { 
      return testContextInstance; 
     } 
     set 
     { 
      testContextInstance = value; 
     } 
    } 

    #region Additional test attributes 
    // 
    //You can use the following additional attributes as you write your tests: 
    // 
    //Use ClassInitialize to run code before running the first test in the class 
    //[ClassInitialize()] 
    //public static void MyClassInitialize(TestContext testContext) 
    //{ 
    //} 
    // 
    //Use ClassCleanup to run code after all tests in a class have run 
    //[ClassCleanup()] 
    //public static void MyClassCleanup() 
    //{ 
    //} 
    // 
    //Use TestInitialize to run code before running each test 
    //[TestInitialize()] 
    //public void MyTestInitialize() 
    //{ 
    //} 
    // 
    //Use TestCleanup to run code after each test has run 
    //[TestCleanup()] 
    //public void MyTestCleanup() 
    //{ 
    //} 
    // 
    #endregion 

} 

我已搜查沒有結果網頁..

有誰知道有什麼問題嗎?

回答

1

顯然,Windows Phone項目不能使用「生成單元測試...」嚮導。

當您嘗試使用嚮導,以下錯誤提示:

While trying to generate your tests, the following errors occurred: 
You can only add WinMD references to a project targeting Windows 8.0 or higher. To learn how to retarget your project to a different version of Windows, please see the 'Core subgroup' section underneath the 'Windows tab' section in the 'How to: add or remove references by using the Reference Manager' help page: http://msdn.microsoft.com/library/hh708954(v=vs.110).aspx. 

你現在可以做的最好的是通過手動創建它。

+0

嗨,@DawaLaw你是發佈者! 那麼,爲什麼你寫這篇文章,如果它不可能? :)) 爲什麼地獄做微軟啓用該功能,如果它不工作..怪異 任何方式,我真的有很多方法,所以我試圖將代碼遷移到VS2010,並生成單元測試那裏.. 但我很難將單元測試項目導回到VS2012。 DLL之間有很多衝突等等。 最糟糕的情況是我會手動完成它。 – Erez 2013-02-13 14:00:34

+0

嗨@Erez,可以使用Windows窗體,控制檯和Web項目生成單元測試。但是,在您發佈這些問題之前,我沒有在Windows Phone項目上進行測試。經過一個小時的研究,無論我嘗試什麼方法都不行。其實微軟禁用了這個功能,它被張貼在[這裏](http://blogs.msdn.com/b/visualstudioalm/archive/2012/03/08/what-s-new-in-visual-studio-11-beta - 單元-testing.aspx)。 我可以建議你創建一個類庫項目,將你的方法/類轉移到該項目中,生成單元測試並更改參考。 – 2013-02-13 14:10:47

+0

好吧,無論如何。 要去這個舊學校..第一次,我正在做單元測試,所以它可能是最好的:) – Erez 2013-02-13 15:42:24