1

因此,与 Visual Studio 2010 相比,右键单击方法时,上下文菜单中没有“创建单元测试”,这让我感到惊讶。

建议的解决方法是在 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

}

我在网上搜索了没有结果..

有人知道这里有什么问题吗?

4

1 回答 1

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.

您现在可以做的最好的事情是手动创建它。

于 2013-02-13T13:39:55.940 回答