【问题标题】:Visual Studio 2012 auto create unit test - WP8 applicationVisual Studio 2012 自动创建单元测试 - WP8 应用程序
【发布时间】:2013-02-13 10:39:51
【问题描述】:

因此,与 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

}

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

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

【问题讨论】:

    标签: unit-testing visual-studio-2012 windows-phone-8


    【解决方案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.
    

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

    【讨论】:

    • 嘿,@DawaLaw 你是帖子作者!那么,如果不可能,您为什么要写那篇文章? :)) 如果它不起作用,为什么微软会启用该功能.. 很奇怪无论如何,我真的有很多方法,所以我试图将代码迁移到 VS2010 并在那里生成单元测试.. 但是我在将单元测试项目导入 VS2012 时遇到问题。 DLL之间的许多冲突等等..最坏的情况我会手动完成。
    • 嗨@Erez,可以使用Windows 窗体、控制台和Web 项目生成单元测试。但是,在您发布此问题之前,我没有在 Windows Phone 项目上进行测试。经过一个小时的研究,无论我尝试什么方法都行不通。实际上微软禁用了这个功能,它被发布在here。我可以建议您创建一个类库项目,将您的方法/类转移到该项目中,生成单元测试并更改参考。
    • 好吧,无论如何,谢谢。我会在这个上去老学校..我第一次做单元测试,所以这可能是最好的:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-16
    • 2014-03-28
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多