Tfs sdk 使用TFS API获取测试结果/结果

Tfs sdk 使用TFS API获取测试结果/结果,tfs-sdk,Tfs Sdk,使用TFSAPI,如何在给定的测试套件和计划中获得特定测试用例的结果/结果 对于结果/结果,我指的是MTM中测试分组的值: 已通过、失败、活动、正在进行或被阻止 您可以使用ITestManagementService和TestPlan查询来获取特定测试计划的结果 var server = new Uri("http://servername:8080/tfs/collectionname"); var tfs = TfsTeamProjectCollectionFactory.G

使用TFSAPI,如何在给定的测试套件和计划中获得特定测试用例的结果/结果

对于结果/结果,我指的是MTM中测试分组的值: 已通过、失败、活动、正在进行或被阻止


您可以使用
ITestManagementService
TestPlan
查询来获取特定测试计划的结果

    var server = new Uri("http://servername:8080/tfs/collectionname");
    var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(server);
    var service = tfs.GetService<ITestManagementService>();
    var testProject = service.GetTeamProject(teamProject);
    var plans = testProject.TestPlans.Query("SELECT * FROM TestPlan").Where(tp => tp.Name == YOURTESTPLANNAME).FirstOrDefault();

   ITestPlanCollection plans = tfsConnectedTeamProject.TestPlans.Query("Select * From TestPlan");
        foreach (ITestPlan plan in plans)
        {
            if (plan.RootSuite != null && plan.RootSuite.Entries.Count > 0)
            {
                foreach (ITestSuiteEntry suiteEntry in plan.RootSuite.Entries)
                {
                    var suite = suiteEntry.TestSuite as IStaticTestSuite;
                    if (suite != null)
                    {
                        ITestSuiteEntryCollection suiteentrys = suite.TestCases;
                        foreach (ITestSuiteEntry testcase in suiteentrys)
                        {
                            // Write code to get the test case 
                        }
                    }
                }
            }
        }
var服务器=新Uri(“http://servername:8080/tfs/collectionname");
var tfs=tfstreamprojectcollectionfactory.GetTeamProjectCollection(服务器);
var service=tfs.GetService();
var testProject=service.GetTeamProject(teamProject);
var plans=testProject.TestPlans.Query(“从TestPlan中选择*)。其中(tp=>tp.Name==YOURTESTPLANNAME)。FirstOrDefault();
ITestPlanCollection plans=tfsConnectedTeamProject.TestPlans.Query(“从测试计划中选择*);
foreach(计划中的ITestPlan计划)
{
if(plan.RootSuite!=null&&plan.RootSuite.Entries.Count>0)
{
foreach(计划中的ITestSuitentry.RootSuite.Entries)
{
var suite=suitentry.TestSuite作为IStaticTestSuite;
if(suite!=null)
{
itestsuitentrycollection suitentrys=suite.TestCases;
foreach(SuiteEntry中的ITestSuiteEntry测试用例)
{
//编写代码以获取测试用例
}
}
}
}
}
我希望这能对你有所帮助。

我就是这样做的

要通过测试,我使用以下方法: ITestRun运行*

run.PassedTests和run.TotalTests

要查看运行状态,请使用:

TestRunSTate.Aborted和TestRunSTate.InProgress

要查看测试是否失败或不确定,我使用:

TestOutput.失败或TestOutput.不确定

首先,我只使用ITestRun来简化se结果,但我发现它们缺少任何类型的“失败”,这让我感到非常不安。 因此,要将正确的数字发送到发送给产品所有者的测试报告中,我在与tfs api交谈时会执行以下操作:

var tfs = Connect(optionsModel.CollectionUri);
var tcm = GetService<ITestManagementService>(tfs);
var wis = GetService<WorkItemStore>(tfs);

_testProject = tcm.GetTeamProject(optionsModel.TeamProjectName);

var plan = _testProject.TestPlans.Find(optionsModel.PlanId);

if (plan == null)
    throw new Exception("Could not find plan with that id.");

var run = plan.CreateTestRun(true);


var testSuite = _testProject.TestSuites.Find(optionsModel.SuiteId);


if (testSuite == null)
            throw new Exception("Could not find suite with that id.");

AddTestCasesBySuite(testSuite, optionsModel.ConfigId, plan, run);

run.Title = optionsModel.Title;
run.Save();

var failedTests = run.QueryResultsByOutcome(TestOutcome.Failed).Count;
var inconclusiveTests = run.QueryResultsByOutcome(TestOutcome.Inconclusive).Count;
var-tfs=Connect(optionsModel.CollectionUri);
var tcm=GetService(tfs);
var wis=获取服务(tfs);
_testProject=tcm.GetTeamProject(optionsModel.TeamProjectName);
var plan=_testProject.TestPlans.Find(optionsModel.PlanId);
如果(计划==null)
抛出新异常(“无法找到具有该id的计划”);
var run=plan.CreateTestRun(true);
var testSuite=_testProject.TestSuites.Find(optionsModel.SuiteId);
if(testSuite==null)
抛出新异常(“找不到具有该id的套件”);
AddTestCasesBySuite(testSuite,optionModel.ConfigId,plan,run);
run.Title=选项model.Title;
run.Save();
var failedTests=run.QueryResultsByOutcome(testoutput.Failed).Count;
var inconclusiveTests=run.QueryResultsByOutcome(testoutput.Inconclusive).Count;
希望这有帮助
optionsmodel是我从运行TST的用户那里获取的信息,我试图做同样的事情,但是使用RESTAPI

为了以防万一,我设法从套件中获取测试点:

https://dev.azure.com/{organization}/{project}/_apis/testplan/Plans/{planId}/Suites/{suiteId}/TestPoint?api-version=5.1-preview.2

更多信息:

您可能想看看这个,谢谢,但这不是我真正想要的。正如我所说的,我想找出给定特定测试用例ID的结果。这个答案不包含如何获得测试用例的结果/结果,只包含如何迭代测试计划和测试套件。