我需要将测试结果添加到VSTS中的测试用例中。我是VSTS的新手,不知道我的代码出了什么问题
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();
我发现this question相似,但得到答案。
我找不到创建Test Suite的选项,然后测试用例。刚刚创建了测试用例。是否要求创建Test Suite?如果是这样,怎么样?
答案 0 :(得分:1)
The test suite is required. There are some ways to create test suite:
Way 1:
Way 2: Using MTM to create test plan, test suite: Organizing Test Cases Using Test Suites.
Note: MTM is include in Visual Studio (e.g. VS Ultimate, Premium, Enterprise (2015) and visual studio test professional).
Way 3:
答案 1 :(得分:1)
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);
}
注意:配置说明
Install-Package Microsoft.TeamFoundationServer.ExtendedClient -Version 15.112.1
在“测试”选项卡中安装测试管理器扩展,创建测试计划,测试套件
testpointid
是TestCase编号(即测试计划中测试用例的顺序/索引),而不是TestCase的ID
name
是测试用例名称,testrun.Id
是通过testpointid自动捕获的(第一个索引为1
)