【问题标题】:In TFS, how do I find all Test Cases in a Test Suite with a query (C#)?在 TFS 中,如何使用查询 (C#) 查找测试套件中的所有测试用例?
【发布时间】:2016-05-06 04:11:58
【问题描述】:

对于 Team Foundation Server,给定类型为“测试套件”的 WorkItem,我如何编写查询来选择与该测试套件关联的所有测试用例?

【问题讨论】:

  • 以编程方式查看this blog post。可能会暗示仅通过查询完成的解决方案。
  • 您是指以编程方式还是仅使用查询构建器工具?您是在使用在线 TFS 还是在本地
  • 查询构建器工具。是的,在在线界面中使用它并下拉到程序中。

标签: c# tfs testcase test-suite


【解决方案1】:

很遗憾,在测试计划、套件和案例之间没有创建工作项链接。因此,尽管它们是工作项,但它们没有链接。这意味着默认查询是不可能的。

解决方法是 tagging all test cases 在具有套件名称的套件中。然后你可以使用a query that filters on the work item tags

您可以更进一步,通过使用Web Hooks and Azure Functions(或其他一些托管 API)魔术来自动创建标签。这允许您创建一个 Web Hook 来侦听测试用例的创建(或更新)。通过使用其他帖子中提到的一些代码,您可以检索测试用例的测试套件,然后使用 REST API 将其作为标签添加到测试用例中。

【讨论】:

  • 我认为你是对的。我们目前正在执行类似的解决方法。在我们的设置中,我们不是用名称标记测试用例(我们将标签用于其他用途),而是在静态套件和正在添加的测试用例之间创建一个链接。然后我们可以查询这些套件,它们的孩子将成为测试用例。不过,我将研究通过网络挂钩的自动创建,这可能比我们当前的自动化解决方案更好。感谢您的想法!
【解决方案2】:

您可能需要使用此接口ITestSuiteBase

AllTestCases 

     Gets the read-only collection of test cases for this suite and all hierarchical children.

TestCases 

     Gets a read-only collection of test cases.

更多信息来自MSDN

这是一个示例代码:

public static List<TestCase> GetAllTestCaseFromSuite(ITestPlan testPlan, int suiteId, bool includeExecutionStatus = true)
{
    List<TestCase> testCases = new List<TestCase>();
    testPlan.Refresh();
    ITestSuiteBase currentSuite = testPlan.Project.TestSuites.Find(suiteId);
    currentSuite.Refresh();
    foreach (var currentTestCase in currentSuite.TestCases)
    {
        TestCase testCaseToAdd = new TestCase(currentTestCase.TestCase, currentSuite, testPlan, includeExecutionStatus);
        if (!testCases.Contains(testCaseToAdd))
        {
            testCases.Add(testCaseToAdd);
        }
    }
    log.InfoFormat("Load all test cases in the suite with Title= \"{0}\" id = \"{1}\"", currentSuite.Title, currentSuite.Id);
    return testCases;
}

更多细节可以参考这个博客:Manage TFS Test Cases C# Code

【讨论】:

  • 我需要一个仅基于查询的解决方案
【解决方案3】:

如果您使用的是 TFS 2015 或更高版本,

你可以查看这个链接:

  1. usage

  2. TestCaseExplorer Tool

  3. list-bugs-and-the-test-cases-that-test-them

如果不使用 TFS 2015 或更高版本:

目前,无法通过 Web 界面创建普通的 TFS 查询,也无法通过 API 调用或自定义编码来获取属于特定测试套件的测试用例列表。 support-querying-for-all-test-cases-in-a-specifed

或尝试旧工具:test-plans-test-suites-test-cases-mapping

【讨论】:

  • 感谢您的回复,但我看不到它在哪里显示如何在给定的测试套件下查询测试用例。现在是 TFS 2015。我真的开始认为这是不可能的。
【解决方案4】:

“显示子套件中的测试”是您想要的选项。 To see the screenshot click here。无需查询。 正如选项的名称所说,它列出了套件中的所有子测试。为此,您可能需要 Test Manager TFS 插件。

【讨论】:

  • 这似乎只是显示了子套件的所有测试用例,这不是我想要的。在这种情况下,查询 sweet 将没有子套件,但会查询一个或多个静态套件,并且基于查询的套件应包含查询中包含的测试套件的所有测试用例。
猜你喜欢
  • 1970-01-01
  • 2018-04-07
  • 1970-01-01
  • 1970-01-01
  • 2020-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多