简体   繁体   English

无法在Visual Studio 2012中运行Windows应用商店应用的单元测试

[英]Cannot Run Unit Tests for Windows Store apps in Visual Studio 2012

I can't seem to run unit tests for Windows store apps using Visual Studio 2012. 我似乎无法使用Visual Studio 2012运行Windows商店应用程序的单元测试。

I have gone through the following steps in order to configure my application. 我已完成以下步骤以配置我的应用程序。

  1. I create a windows store project. 我创建了一个Windows商店项目。 I build it and get it to run just fine. 我建立它并让它运行得很好。
  2. I than right click on the solution and click Add > New Project. 我右键单击解决方案,然后单击添加>新建项目。 From the 'Add New Project Menu' I select the project template 'Unit Test Library (Windows Store apps) and click okay creating the project. 从“添加新项目菜单”中选择项目模板“单元测试库(Windows应用商店应用)”,然后单击“确定”创建项目。
  3. I create a basic unit test that looks something like the following. 我创建了一个类似于以下内容的基本单元测试。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;

namespace UnitTestLibrary1
{
  [TestClass]
  public class UnitTest1
  {
    [TestMethod]
    public void TestMethod1()
    {
      string a = "a";
      string b = "b";

      Assert.AreEqual(a, b);
    }
  }
}

**Note as per the instructions found on the MSDN website here I have not built the Unit Test project yet **请注意,根据MSDN网站上说明,我还没有构建单元测试项目

4 - I open the Visual Studio test explore which displays the following. 4 - 我打开Visual Studio test explore,它显示以下内容。

在此输入图像描述

5 - I proceed to build the entire solution (below is the build output) 5 - 我继续构建整个解决方案(下面是构建输出)

1>------ Build started: Project: vevo.pushclient, Configuration: Debug Any CPU ------
2>------ Build started: Project: UnitTestLibrary1, Configuration: Debug Any CPU ------
2>  UnitTestLibrary1 -> C:\Source\simple_push_client\vevo.pushclient\UnitTestLibrary1\bin\Debug\UnitTestLibrary1.dll
1>  vevo.pushclient -> C:\Source\simple_push_client\vevo.pushclient\vevo.pushclient\bin\Debug\vevo.pushclient.exe
========== Build: 2 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

The following was the output from Tests, I tried googling the error but could not find any helpful answers 以下是测试的输出,我尝试使用谷歌搜索错误,但找不到任何有用的答案

------ Discover test started ------
MSTestAdapter failed to discover tests in class 'UnitTestLibrary1.UnitTest1' of assembly 'C:\Source\simple_push_client\vevo.pushclient\UnitTestLibrary1\bin\Debug\UnitTestLibrary1.dll'. Reason Method not found: 'System.String Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestCategoryBaseAttribute.get_TestCategory()'..
NUnit 0.97.0.0 discovering tests is started
NUnit 0.97.0.0 discovering test is finished
========== Discover test finished: 0 found (0:00:00.1800223) ==========

The Test Explorer still showed the same message as before the build that stated 'Build your solution to discover all available tests.... 测试资源管理器仍然显示与构建之前相同的消息,声明“构建您的解决方案以发现所有可用的测试....

Even so I tried clicking run all. 即便如此,我也试过点击全部运行。

This resulted in the following output for the build 这导致构建的以下输出

========== Build: 0 succeeded, 0 failed, 2 up-to-date, 0 skipped ==========

And no output for Tests 没有测试输出

Needless to say no tests were shown as having been run, passed, skipped, or failed in the test explorer. 毋庸置疑,测试资源管理器中没有显示测试已经运行,通过,跳过或失败。

I ensured that the configuration Properties of the UnitTest project were set to build and deploy and attempted to build using each platform configuration (Any CPU, x86, and x4) 我确保将UnitTest项目的配置属性设置为构建和部署,并尝试使用每个平台配置(任何CPU,x86和x4)进行构建

在此输入图像描述

It tells you that you are missing an attribute on your test methods... 它告诉您,您缺少测试方法的属性...

MSTestAdapter failed to discover tests in class 'UnitTestLibrary1.UnitTest1' of assembly 'C:\\Source\\simple_push_client\\vevo.pushclient\\UnitTestLibrary1\\bin\\Debug\\UnitTestLibrary1.dll'. MSTestAdapter未能在程序集“C:\\ Source \\ simple_push_client \\ vevo.pushclient \\ UnitTestLibrary1 \\ bin \\ Debug \\ UnitTestLibrary1.dll”的类“UnitTestLibrary1.UnitTest1”中发现测试。 Reason Method not found: 'System.String Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestCategoryBaseAttribute.get_TestCategory()'.. 找不到原因方法:'System.String Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestCategoryBaseAttribute.get_TestCategory()'..

Not sure why, it shouldn't be required. 不知道为什么,它不应该被要求。 But add the attribute: 但是添加属性:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;

namespace UnitTestLibrary1
{
  [TestClass]
  public class UnitTest1
  {
    [TestMethod]
    [TestCategory("tests")]    <! -- Added Attribute -->
    public void TestMethod1()
    {
      string a = "a";
      string b = "b";

      Assert.AreEqual(a, b);
    }
  }
}

The Category can be whatever you want. 类别可以是您想要的任何内容。 Not sure why its doing that, Category should be an optional parameter. 不确定为什么这样做,Category应该是一个可选参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM