在TFS中,如何使用查询(C#)查找测试套件中的所有测试用例?

时间:2016-01-28 16:53:59

标签: c# tfs testcase test-suite

使用Team Foundation Server,给定一个类型为" Test Suite的工作项,"如何编写查询以选择与该Test Suite关联的所有测试用例?

4 个答案:

答案 0 :(得分:5)

不幸的是,测试计划,套件和案例之间没有创建工作项链接。因此,虽然它们是工作项,但它们没有链接。这意味着无法进行默认查询。

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

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

答案 1 :(得分:1)

您可能需要使用此界面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

答案 2 :(得分:1)

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

您可以查看此链接:

  1. usage

  2. TestCaseExplorer Tool

  3. list-bugs-and-the-test-cases-that-test-them enter image description here

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

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

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

答案 3 :(得分:0)

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