将测试结果添加到VSTS中的测试运行(测试用例) [英] Add Test Result to a test run(testcase) in VSTS
问题描述
我需要将测试结果添加到VSTS的测试用例中.我是VSTS的新手,不确定我的代码出了什么问题
I need to add test result to a testcase in VSTS. I'm new to VSTS and not sure what went wrong with my code
var ur = new Uri("https://{myaccount}.visualstudio.com");
VssCredentials cr = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "XXXXX"));
var connection = new VssConnection(ur, cr);
var testClient = connection.GetClient<TestManagementHttpClient>();
int testpointid = 123;
string teamProject = "myproj";
RunCreateModel run = new RunCreateModel(name: "name123", plan: new Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference("123"), pointIds: new int[] { testpointid });
TestRun testrun = testClient.CreateTestRunAsync(run, teamProject).Result;
Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference("100000") };
TestCaseResult caseResult = new TestCaseResult() { State = "Completed", Outcome = "passed", Id = 100000 };
var testResults = testClient.UpdateTestResultsAsync(new TestCaseResult[] { caseResult }, teamProject, testrun.Id).Result;
RunUpdateModel runmodel = new RunUpdateModel(state: "Completed");
TestRun testRunResult = testClient.UpdateTestRunAsync(runmodel, teamProject, testrun.Id, runmodel).Result;
Console.WriteLine("Success");
Console.ReadKey();
I find this question similar but dint get answer.
我找不到创建Test Suite然后在其中测试用例的选项.刚刚直接创建了测试用例.创建测试套件是强制性的吗?如果可以,怎么办?
I don't find option to create Test Suite and then test case in that. Just created test case directly. Is it mandate to create Test Suite? If so, how?
推荐答案
try
{
var u = new Uri("https://{My Account}.visualstudio.com");
VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "PAT"));
var connection = new VssConnection(u, c);
var testClient = connection.GetClient<TestManagementHttpClient>();
int testpointid = 1;
string teamProject = "MyProjectName";
RunCreateModel run = new RunCreateModel(name: "TestCase Name", plan: new Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference("TestPlan Id"), pointIds: new int[] { testpointid });
TestRun testrun = testClient.CreateTestRunAsync(run, teamProject).Result;
TestCaseResult caseResult = new TestCaseResult() { State = "Completed", Outcome = "passed", Id = 100000 };
var testResults = testClient.UpdateTestResultsAsync(new TestCaseResult[] { caseResult }, teamProject, testrun.Id).Result;
RunUpdateModel runmodel = new RunUpdateModel(state: "Completed");
TestRun testRunResult = testClient.UpdateTestRunAsync(runmodel, teamProject, testrun.Id, runmodel).Result;
}
catch (AggregateException e)
{
Console.WriteLine(e.InnerException.Message);
}
注意:配置说明
- 安装Microsoft Team Foundation Server扩展客户端软件包
Install-Package Microsoft.TeamFoundationServer.ExtendedClient -Version 15.112.1
-
安装测试管理器"扩展程序,在测试"选项卡中创建测试计划,测试套件
Install Test Manager extension, Create test plan, test suite in Test tab
testpointid
是TestCase编号(即测试计划中测试用例的顺序/索引),而不是TestCase的ID
testpointid
is TestCase number (i.e. order/index of testcase in test plan) and not the ID of the TestCase
name
是测试用例名称,testrun.Id
是通过testpointid(第一个索引为1
)自动捕获的
name
is Testcase name, testrun.Id
is auto-captured through testpointid (first index being 1
)
这篇关于将测试结果添加到VSTS中的测试运行(测试用例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!