【问题标题】:Show Test result Form test suites using TFS api使用 TFS api 显示测试结果表单测试套件
【发布时间】:2014-03-11 01:51:07
【问题描述】:

我正在处理一个学校项目,我将在其中分析公司缺陷数据库。 他们正在使用 Microsoft Foundation Server (TFS)。 我是 TFS 和 TFS api 的新手。

我在使用 TFS 客户端对象模型从 TFS 获取正确数据时遇到了一些问题 . 我可以检索所有测试计划、它们各自的测试套件以及特定测试套件使用的每个测试用例,但是当我想查看在哪个测试套件中我有来自测试用例的特定测试结果时,问题就来了。由于该套件可以使用多个相同的测试用例,因此我无法看到结果来自哪个套件。

我这样做是为了从套件中获取测试用例:

foreach (ITestSuiteEntry testcase in suiteEntrys)
{
    Console.WriteLine("\t \t Test Case: {0}", testcase.Title+", "+"Test case priority: "+ testcase.TestCase.Priority+"Test case Id: "+testcase.TestCase.Id);
    //Console.Write(", Test Case: {0}", testcase.ToString());

    //get each test result:
    getTestResult(testcase,proj);
}

private void getTestResult(ITestSuiteEntry testcase, ITestManagementTeamProject proj)
{
    var testResults = proj.TestResults.ByTestId(testcase.TestCase.Id);
    foreach (ITestCaseResult result in testResults)
    {
        Console.WriteLine("\t \t \t"+result.DateCreated+","+result.Outcome);
    }
}

所以我的问题是,如何查看用于执行测试的测试套件?

【问题讨论】:

  • 我不太确定,因为最近几天我没有深入研究 API 的这一部分,但我记得 ITestPoint/TestPointId 实际上将测试结果链接到测试套件。
  • 这篇博文也可以帮助你转发:blogs.msdn.com/b/densto/archive/2010/03/04/…

标签: tfs-sdk microsoft-test-manager test-suite


【解决方案1】:

看看下面的代码 sn-p。
它向您展示了如何使用 测试点 ID 获取特定 测试套件测试结果
您可以使用类似的方法来实现您的目标。

var tfsCollection = new TfsTeamProjectCollection(
        new Uri(tfsUrl),
        new System.Net.NetworkCredential(<user>, <password>));
tfsCollection.EnsureAuthenticated();

var testManagementService = tfsCollection.GetService<ITestManagementService>();
var teamProject = testManagementService.GetTeamProject(projectName);
var testPlan = teamProject.TestPlans.Find(testPlanId);

// Get all Test Cases belonging to a particular Test Suite.
// (If you are using several Test Configurations and want to take only one of them into account,
// you will have to add 'AND ConfigurationId = <your Test Configuration Id>' to the WHERE clause.)
string queryForTestPointsForSpecificTestSuite = string.Format("SELECT * FROM TestPoint WHERE SuiteId = {0}", suiteId );
var testPoints = testPlan.QueryTestPoints(queryForTestPointsForSpecificTestSuite);
// We are going to use these ids when analyzing Test Results
List<int> testPointsIds = (from testPoint in testPoints select testPoint.Id).ToList();

var testResults = teamProject.TestResults.ByTestId(testCaseId);

var testResultsForSpecificTestSuite = testResults.Where(testResult => testPointsIds.Contains(testResult.TestPointId));

这篇博文将帮助您创建查询:WIQL for Test

【讨论】:

  • 我在 testManagementService 上得到 nullpointerexception。任何想法为什么?
  • @mosaad 请提供更多信息。你的意思是你得到一个 NullReference 异常?什么时候收到?
  • 我修复了它,以防有人遇到同样的问题,我忘记将 url 从基本 url 更改为集合之一,因此找不到测试管理服务
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-10
  • 2015-12-25
  • 1970-01-01
  • 1970-01-01
  • 2020-03-24
  • 1970-01-01
相关资源
最近更新 更多