如何将测试方法与测试用例相关联? [英] How do I associate test methods to test cases?

查看:134
本文介绍了如何将测试方法与测试用例相关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Test Explorer中将测试方法与测试用例相关联(与测试用例相关联的选项"显示为灰色),也无法通过MTM或VSTS网站进行关联.我根本找不到一种将测试与测试用例关联以进行自动化测试的方法.

I am unable to associate test methods to test cases in the Test Explorer (the "Associate to Test Case" option is greyed out), or via MTM, or the VSTS website. I simply cannot find a way to associate tests to the test cases for automated testing.

我正在使用.NET核心应用程序1.1,使用MSTest的ASP.NET(尽管我也尝试过Xunit,但无济于事).即使总是通过的基本测试用例也无法关联.

I am using .NET core app 1.1, ASP.NET using MSTest (though I have tried Xunit as well, to no avail). Even a basic test case that always passes cannot be associated.

在MTM中,我创建了一个测试计划,该计划的自动化状态"设置为计划".

In MTM, I have created a test plan that has the Automation Status set to "Plan".

在VSTS中,我有一个使用Git存储库的项目,在其中创建了可以成功发现,运行和报告测试的CI构建.

In VSTS, I have a project using a Git repository, in which I have a CI build created that successfully discovers, runs and reports the tests.

我找不到将这些特定测试与测试运行相关联的位置.我该怎么办?

I cannot find where to associate these specific tests to test runs. How may I accomplish this?

推荐答案

请参阅以下步骤,将测试方法与测试用例相关联:

Refer to these steps to associate test method to test case:

  1. 安装MTM 2017(运行VS 2017安装应用程序(vs_Enterprise.exe)>``修改'')​​

  1. 打开VS 2017>工具>选项>工作项>常规>在以下位置打开工作项选择Visual Studio(兼容模式):

  1. 在VS 2017中打开测试项目并进行构建
  2. 打开团队资源管理器并连接到您的团队项目
  3. 在搜索工作项"框中键入测试用例ID>按Enter键打开测试用例
  4. 选择关联的自动化"选项卡,然后单击"...".
  5. 选择一种测试方法>确定
  6. 保存测试用例工作项

另一种方法是,可以通过更新字段REST API"将测试方法与测试用例相关联.

Another way is that you can associate the test method with test case through Update a field REST API.

例如:

PATCH https://[account].visualstudio.com/DefaultCollection/_apis/wit/workitems/[testcaseid]?api-version=1.0

Content-Type:application/json-patch+json

Content-Type: application/json-patch+json

身体:

[
  {
    "op": "add",
    "path": "/fields/Microsoft.VSTS.TCM.AutomatedTestName",
    "value": "[namespace.classname.methodname (e.g. UnitTestProject1.UnitTest1.TestMethod2)]"
  },
  {
    "op": "add",
    "path": "/fields/Microsoft.VSTS.TCM.AutomatedTestStorage",
    "value": "[assembly name(e.g. unittestproject1.dll)"
  },
  {
    "op": "add",
    "path": "/fields/Microsoft.VSTS.TCM.AutomatedTestId",
    "value": "[guid id]"
  },
  {
    "op": "add",
    "path": "/fields/Microsoft.VSTS.TCM.AutomatedTestType",
    "value": "Unit Test"
  },
   {
    "op": "add",
    "path": "/fields/Microsoft.VSTS.TCM.AutomationStatus",
    "value": "Automated"
  }
]

AutomatedTestId是Guid值,因此您可以使用以下C#代码生成新的Guid:

The AutomatedTestId is a Guid value, so you can generate a new Guid by using this C# code:

Guid g = Guid.NewGuid();
string s = g.ToString();

这篇关于如何将测试方法与测试用例相关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆