static void Main(string[] args) { TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("https://code-inside.visualstudio.com/DefaultCollection")); ITestManagementService testManagement = (ITestManagementService)tfs.GetService(typeof(ITestManagementService)); // WIQL for Test: http://blogs.msdn.com/b/duat_le/archive/2010/02/25/wiql-for-test.aspx?Redirected=true string query = "SELECT * FROM TestRun WHERE TestRun.CompleteDate > '" + DateTime.Now.AddDays(-3).Year + "-" + DateTime.Now.AddDays(-3).Month + "-" + DateTime.Now.AddDays(-3).Day + "'"; var testRuns = testManagement.QueryTestRuns(query); foreach (var testPlan in testRuns) { Console.WriteLine("------------------"); Console.WriteLine("TestPlan-Title: {0}", testPlan.Title); Console.WriteLine("Overall State: {0}", testPlan.State); Console.WriteLine("Overall DateCreated: {0}", testPlan.DateCreated); Console.WriteLine("Overall PassedTests: {0}", testPlan.PassedTests); var testRunResults = testPlan.QueryResults(); Console.WriteLine("Test Run Results:"); foreach (var testRunResult in testRunResults) { Console.WriteLine(" TestRun: {0}", testRunResult.TestCaseTitle); Console.WriteLine(" State: {0}", testRunResult.State); if (testRunResult.TestCaseId != 0) { var testCaseDetail = testManagement.GetTeamProject("Grocerylist").TestCases.Find(testRunResult.TestCaseId); foreach (var steps in testRunResult.Iterations) { foreach (var action in steps.Actions) { var actionFromTestCase = (ITestStep)testCaseDetail.FindAction(action.ActionId); Console.WriteLine(" " + actionFromTestCase.Title + " : " + action.Outcome); } } } else { Console.WriteLine(" No TestCase behind this Testrun"); } } } Console.ReadLine(); }
internal long CalcSize(ref TeamProjectAttachemntInfo fld, string timeUnitFormat) { ITestManagementTeamProject tp = testSvc.GetTeamProject(fld.TeamProjectName); long size = 0; IEnumerable <ITestRun> lst = testSvc.QueryTestRuns(string.Format("SELECT * FROM TestRun WHERE TeamProject = '{0}' ", fld.TeamProjectName)); foreach (ITestRun tr in lst) { long curSize = CalcSizeInRuns(tp, tr, ref fld); size += curSize; string timeUnit = String.Format(timeUnitFormat, tr.DateCreated); fld.AddValueToKey(ref fld._time, timeUnit, curSize); } return(size); }
/// <summary> /// Get the results associated with a test case /// </summary> /// <param name="stub">The work item to get the results for</param> private void GetTestResults(WorkItemStub stub, string project) { //Return all of the test results in which this test case was executed string query = string.Format("SELECT * FROM TestResult WHERE TestCaseId = {0}", stub.ID); int planId = 0; //Get the list of results for the test case foreach (ITestCaseResult tcr in _tmp.TestResults.Query(query)) { #region Get the Test Plan string runQuery = string.Format("SELECT * FROM TestRun WHERE TestRunId = {0}", tcr.TestRunId); //There should only be one value returned so just get the first one foreach (ITestRun tr in _tms.QueryTestRuns(runQuery)) { planId = tr.TestPlanId; break; } //Is this part of a test plan that we already have? TestPlanInfo plan = _testPlans.Find( delegate(TestPlanInfo tpi) { return(tpi.TestPlanID == planId); } ); //If not, add it if (plan == null) { string planQuery = string.Format("SELECT * FROM TestPlan WHERE PlanId = {0}", planId); foreach (ITestPlan testPlan in _tmp.TestPlans.Query(planQuery)) { plan = new TestPlanInfo() { TestPlanID = planId, TestPlanName = testPlan.Name }; _testPlans.Add(plan); break; } } #endregion //Check to see if we've added the test run already bool found = false; for (int k = 0; k < plan.TestRuns.Count; k++) { if (plan.TestRuns[k].ID == tcr.TestRunId) { found = true; } } //If not, add it if (!found) { plan.TestRuns.Add(new TestRunStub() { ID = tcr.TestRunId, Url = GetURL(UrlType.TestRun, tcr.TestRunId, 0, project) }); } //add the results TestResultStub resultStub = new TestResultStub(); resultStub.TestPlan = plan; resultStub.TestCaseID = tcr.TestCaseId; resultStub.TestResultID = tcr.TestResultId; resultStub.TestRunID = tcr.TestRunId; resultStub.Outcome = tcr.Outcome; resultStub.Url = GetURL(UrlType.TestResult, tcr.TestRunId, tcr.TestResultId, project); stub.TestResults.Add(resultStub); } }