private long GetLastUpdatedAsTicks(ITestPointCollection collection) { var leader = DateTime.Now.AddDays(-100000); foreach (var point in collection) { if (DateTime.Compare(point.TestCaseWorkItem.DateModified, leader) == 1) leader = point.TestCaseWorkItem.DateModified; } return leader.Ticks; }
public void Initialize(ITestPlan testPlan, ITestManagementTeamProject testProject, string tfsUrl, string project) { ITestPointCollection testPlanPoints = testPlan.QueryTestPoints("SELECT * FROM TestPoint"); dataSet = new DataSet(); foreach (ITestPoint item in testPlanPoints) { int priority = item.TestCaseWorkItem.Priority; string testCasePath = string.Format(TestCasePath, item.Plan.Id, item.SuiteId); string testCaseUrl = string.Format(TestCaseUrlBase, tfsUrl, project, testCasePath); TestCaseDescription testCaseDescription = new TestCaseDescription(item, testCaseUrl, testCasePath); dataSet.AddCasePriority(priority, testCaseDescription); if (item.IsTestCaseAutomated) { dataSet.Automated.Add(testCaseDescription); } switch (item.State) { case TestPointState.InProgress: dataSet.InProgress.Add(testCaseDescription); break; case TestPointState.Ready: dataSet.Ready.Add(testCaseDescription); break; case TestPointState.Completed: dataSet.Complete.Add(testCaseDescription); break; } switch (item.AssignedToName) { case "Unassigned": dataSet.Unassigned.Add(testCaseDescription); break; case "Automation User": dataSet.Automated.Add(testCaseDescription); break; default: dataSet.Assigned.Add(testCaseDescription); break; } } DatasetChanged(); }
// Mark result in MTM private void MarkResultMethod() { TfsTeamProjectCollection teamCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://mseng.visualstudio.com:443/defaultcollection")); ITestManagementTeamProject project = teamCollection.GetService <ITestManagementService>().GetTeamProject("VSOnline"); var service = teamCollection.GetService <ITestManagementService>(); ITestPlan plan = project.TestPlans.Find(Convert.ToInt32(txtProjectID.Text)); // Create a new test run ITestRun testRun = plan.CreateTestRun(true); // Add the certain a test to the run string query = string.Format("SELECT * from TestPoint where SuiteID='{0}'", txtSuitID.Text); ITestPointCollection testPoints = plan.QueryTestPoints(query); List <string> failedCaceMTM = new List <string>(); foreach (ITestPoint testPoint in testPoints) { // for caseId please type: testPoint.TestCaseId testRun.AddTestPoint(testPoint, null); //string caseName = testPoint.TestCaseWorkItem.Implementation.DisplayText; //string cname = caseName.Substring(caseName.LastIndexOf(".") + 1); //if (GetFailedCaseNamesListFromTrxFile.Contains(cname)) //{ // failedCaceMTM.Add(cname); //} } var blockCase = GetFailedCaseNamesListFromTrxFile.Except(failedCaceMTM).ToList(); testRun.Save(); //Update the outcome of the test ITestCaseResultCollection results = testRun.QueryResults(); ; foreach (ITestCaseResult result in results) { // Get case name in MTM. string caseName = result.Implementation.DisplayText; string name = caseName.Substring(caseName.LastIndexOf(".") + 1); result.Outcome = GetFailedCaseNamesListFromTrxFile.Contains(name) ? TestOutcome.Passed : TestOutcome.Failed; result.State = TestResultState.Completed; result.Save(); } testRun.Save(); testRun.Refresh(); File.Delete(xmlPath); }
public TestOutcome GetLastTestOutcome(int testPlanId, int suiteId, int testId, int configurationId) { ITestPlan plan = TfsShared.Instance.SourceTestProject.TestPlans.Find(testPlanId); ITestPointCollection tpc = plan.QueryTestPoints("SELECT * FROM TestPoint WHERE SuiteId = " + suiteId); var testPoints = tpc.FirstOrDefault(t => t.TestCaseId.Equals(testId) && t.ConfigurationId.Equals(configurationId)); if (testPoints == null) { return(TestOutcome.None); } return(testPoints.MostRecentResultOutcome); }
//create test point public static ITestPoint CreateTestPoints(ITestPlan testPlan, ITestSuiteBase suite, ITestCase testcase) { try { ITestPointCollection tpc = testPlan.QueryTestPoints("SELECT * FROM TestPoint WHERE SuiteId = " + suite.Id + " and TestCaseID =" + testcase.Id); ITestPoint tp = testPlan.FindTestPoint(tpc[0].Id); return(tp); } catch (Exception e) { throw e; } }
public static IList <ITestPoint> CreateTestPoints(ITestManagementTeamProject project, ITestPlan testPlan, IList <ITestCase> testCases, IList <IdAndName> testConfigs) { IStaticTestSuite testSuite = CreateTestSuite(project); testPlan.RootSuite.Entries.Add(testSuite); testPlan.Save(); testSuite.Entries.AddCases(testCases); testPlan.Save(); testSuite.SetEntryConfigurations(testSuite.Entries, testConfigs); testPlan.Save(); ITestPointCollection tpc = testPlan.QueryTestPoints("SELECT * FROM TestPoint WHERE SuiteId = " + testSuite.Id); return(new List <ITestPoint>(tpc)); }
public void AddTestRun(int suiteId, int testCaseId, ResultState caseResult, string errorOuput, string comment) { if (RunData.Testrun == null) { throw new Exception("InitializeTestRun method has not been called, please call this at the start of the test run"); } //Get test points ITestPointCollection testpoints = RunData.Plan.QueryTestPoints("SELECT * FROM TestPoint WHERE SuiteId = " + suiteId + " and TestCaseId = " + testCaseId); foreach (ITestPoint tp in testpoints) { RunData.Testrun.AddTestPoint(tp, null); } RunData.RunCacheData.Add(new RunCache() { CaseResult = caseResult, Comment = comment, ErrorOutput = errorOuput }); }
// ReSharper disable once RedundantAssignment private ITestCaseResultCollection CreateTestRun(DateTime started, DateTime finished, ITestPointCollection allPoints, ref int createdTestrunId, bool isBuildVerifcationTest = false) { var owner = _tfsBase.TestManagementService.TfsIdentityStore.FindByTeamFoundationId(allPoints.First().TestCaseWorkItem.OwnerTeamFoundationId); var run = allPoints.First().Plan.CreateTestRun(false); run.IsBvt = isBuildVerifcationTest; run.DateStarted = _tfsBase.GetNorwegianTime(started); run.DateCompleted = _tfsBase.GetNorwegianTime(finished); run.AddTestPoints(allPoints, owner); run.Save(); createdTestrunId = run.Id; return(run.QueryResults()); }