2014-02-12 42 views
5

我正在与一家学校项目合作,我将分析一家公司的缺陷数据库。 他们正在使用Microsoft Foundation Server(TFS)。 我都是新来的TFS和TFS api。显示测试结果使用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); 
    } 
} 

所以我的问题是,我怎么能看到这是用来执行测试的测试套件?

+0

我不能完全肯定,因为我还没有深入研究在最近几天的API的一部分,但我记得' ITestPoint' /'TestPointId'实际上将测试结果链接到测试套件。 – jessehouwing

+0

这篇博文可能也会帮助你转发:http://blogs.msdn.com/b/densto/archive/2010/03/04/the-test-management-api-part-2-creating-modifying-test- plans.aspx?Redirected = true – jessehouwing

回答

8

看看下面的代码片段。
它表明你如何获得测试结果使用测试点IDS特定测试套件
您可以使用类似的方法来实现您的目标。

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

+0

是的,这解决了我的问题,thnaks非常多。 – user1418385

+0

非常欢迎:-) – Elena

+0

我在testManagementService上得到了nullpointerexception。任何想法为什么? – mosaad