private void SaveNewTestSuitToPlan(ITestPlan testPlan, IStaticTestSuite parent, ITestSuiteBase newTestSuite) { Trace.WriteLine( $" Saving {newTestSuite.TestSuiteType} : {newTestSuite.Id} - {newTestSuite.Title} ", "TestPlansAndSuites"); try { ((IStaticTestSuite)parent).Entries.Add(newTestSuite); } catch (TestManagementServerException ex) { Telemetry.Current.TrackException(ex, new Dictionary <string, string> { { "Name", Name }, { "Target Project", me.Target.Name }, { "Target Collection", me.Target.Collection.Name }, { "Source Project", me.Source.Name }, { "Source Collection", me.Source.Collection.Name }, { "Status", Status.ToString() }, { "Task", "SaveNewTestSuitToPlan" }, { "Id", newTestSuite.Id.ToString() }, { "Title", newTestSuite.Title }, { "TestSuiteType", newTestSuite.TestSuiteType.ToString() } }); Trace.WriteLine(string.Format(" FAILED {0} : {1} - {2} | {3}", newTestSuite.TestSuiteType.ToString(), newTestSuite.Id, newTestSuite.Title, ex.Message), "TestPlansAndSuites"); ITestSuiteBase ErrorSuitChild = targetTestStore.Project.TestSuites.CreateStatic(); ErrorSuitChild.TestSuiteEntry.Title = string.Format(@"BROKEN: {0} | {1}", newTestSuite.Title, ex.Message); ((IStaticTestSuite)parent).Entries.Add(ErrorSuitChild); } testPlan.Save(); }
public async void CreatePlan() { await Task.Factory.StartNew(() => { if (string.IsNullOrEmpty(TestPlanName)) { MessageBox.Show("Please enter valid test plan name", "Missing Value", MessageBoxButton.OK, MessageBoxImage.Error); return; } Working = true; ITestPlan plan = TfsShared.Instance.TargetTestProject.TestPlans.Create(); plan.Name = TestPlanName; plan.Save(); App.Current.Dispatcher.Invoke(() => { TestPlans.Add(new TestObjectViewModel(plan.RootSuite, false)); }); Working = false; }); }
private ITestPlan CreateNewTestPlanFromSource(ITestPlan sourcePlan, string newPlanName) { ITestPlan targetPlan; targetPlan = targetTestStore.CreateTestPlan(); targetPlan.CopyPropertiesFrom(sourcePlan); targetPlan.Name = newPlanName; targetPlan.StartDate = sourcePlan.StartDate; targetPlan.EndDate = sourcePlan.EndDate; targetPlan.Description = sourcePlan.Description; // Set area and iteration to root of the target project. // We will set the correct values later, when we actually have a work item available targetPlan.Iteration = engine.Target.Name; targetPlan.AreaPath = engine.Target.Name; // Remove testsettings reference because VSTS Sync doesn't support migrating these artifacts if (targetPlan.ManualTestSettingsId != 0) { targetPlan.ManualTestSettingsId = 0; targetPlan.AutomatedTestSettingsId = 0; Trace.WriteLine("Ignoring migration of Testsettings. Azure DevOps Migration Tools don't support migration of this artifact type."); } // Remove reference to build uri because VSTS Sync doesn't support migrating these artifacts if (targetPlan.BuildUri != null) { targetPlan.BuildUri = null; Trace.WriteLine(string.Format("Ignoring migration of assigned Build artifact {0}. Azure DevOps Migration Tools don't support migration of this artifact type.", sourcePlan.BuildUri)); } return(targetPlan); }
/// <summary> /// Sets the new execution outcome. /// </summary> /// <param name="currentTestCase">The current test case.</param> /// <param name="testPlan">The test plan.</param> /// <param name="newExecutionOutcome">The new execution outcome.</param> /// <param name="comment">The comment.</param> /// <param name="testCaseRuns">The test case runs.</param> public static void SetNewExecutionOutcome(this TestCase currentTestCase, ITestPlan testPlan, TestCaseExecutionType newExecutionOutcome, string comment, Dictionary <int, TestCaseRun> testCaseRuns) { if (currentTestCase.ITestCase.Owner == null) { return; } var testPoints = testPlan.QueryTestPoints(string.Format("SELECT * FROM TestPoint WHERE TestCaseId = {0} ", currentTestCase.Id)); var testRun = testPlan.CreateTestRun(false); currentTestCase.IsRunning = string.Empty; DateTime startedDate = DateTime.Now; DateTime lastStartedDate = DateTime.Now; DateTime endDate = DateTime.Now; TimeSpan durationBeforePauses = new TimeSpan(); if (testCaseRuns.ContainsKey(currentTestCase.Id)) { lastStartedDate = testCaseRuns[currentTestCase.Id].LastStartedTime; startedDate = testCaseRuns[currentTestCase.Id].StartTime; durationBeforePauses = testCaseRuns[currentTestCase.Id].Duration; testCaseRuns.Remove(currentTestCase.Id); } testRun.DateStarted = startedDate; testRun.AddTestPoint(testPoints.Last(), ExecutionContext.TestManagementTeamProject.TestManagementService.AuthorizedIdentity); TimeSpan totalDuration = new TimeSpan((DateTime.Now - lastStartedDate).Ticks + durationBeforePauses.Ticks); testRun.DateCompleted = endDate; testRun.Save(); var result = testRun.QueryResults()[0]; result.Owner = ExecutionContext.TestManagementTeamProject.TestManagementService.AuthorizedIdentity; result.RunBy = ExecutionContext.TestManagementTeamProject.TestManagementService.AuthorizedIdentity; result.State = TestResultState.Completed; result.DateStarted = startedDate; result.Duration = totalDuration; result.DateCompleted = endDate; result.Comment = comment; switch (newExecutionOutcome) { case TestCaseExecutionType.Active: result.Outcome = TestOutcome.None; result.Duration = new TimeSpan(); break; case TestCaseExecutionType.Passed: result.Outcome = TestOutcome.Passed; break; case TestCaseExecutionType.Failed: result.Outcome = TestOutcome.Failed; break; case TestCaseExecutionType.Blocked: result.Outcome = TestOutcome.Blocked; break; } result.Save(); }
public void CopyTestPlans() { int planCount = sourceTestMgmtProj.TestPlans.Query("Select * From TestPlan").Count; //delete Test Plans if any existing test plans. //foreach (ITestPlan destinationplan in destinationproj.TestPlans.Query("Select * From TestPlan")) //{ // System.Diagnostics.Debug.WriteLine("Deleting Plan - {0} : {1}", destinationplan.Id, destinationplan.Name); // destinationplan.Delete(DeleteAction.ForceDeletion); ; //} foreach (ITestPlan sourceplan in sourceTestMgmtProj.TestPlans.Query("Select * From TestPlan")) { System.Diagnostics.Debug.WriteLine($"Plan - {sourceplan.Id} : {sourceplan.Name}"); ITestPlan destinationplan = targetTestMgmtProj.TestPlans.Create(); destinationplan.Name = sourceplan.Name; destinationplan.Description = sourceplan.Description; destinationplan.StartDate = sourceplan.StartDate; destinationplan.EndDate = sourceplan.EndDate; destinationplan.State = sourceplan.State; destinationplan.Save(); //drill down to root test suites. if (sourceplan.RootSuite != null && sourceplan.RootSuite.Entries.Count > 0) { CopyTestSuites(sourceplan, destinationplan); } destinationplan.Save(); } }
//Copy all Test suites from source plan to destination plan. private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan) { ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries; CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite); foreach (ITestSuiteEntry suite_entry in suites) { IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite; if (suite != null) { IStaticTestSuite newSuite = destinationproj.TestSuites.CreateStatic(); newSuite.Title = suite.Title; //foreach (var tpoint in newSuite.TestSuiteEntry.PointAssignments) //{ // tpoint.AssignedTo = UserID; //} destinationplan.RootSuite.Entries.Add(newSuite); destinationplan.Save(); CopyTestCases(suite, newSuite); if (suite.Entries.Count > 0) { CopySubTestSuites(suite, newSuite); } } } }
internal int GetNumberOfAutomatedTests(ITestPlan plan, string state) { var collection = plan.QueryTestPoints("SELECT * From TestPoint"); var result = new HashSet <int>(); foreach (var point in collection) { if (result.Contains(point.TestCaseId)) { continue; } var testCase = point.TestCaseWorkItem; var automationStatus = testCase.CustomFields.TryGetById(10030); if (testCase.State != state) { continue; } var isAutomatedTest = automationStatus != null && automationStatus.Value.Equals("Planned"); if (!isAutomatedTest) { continue; } result.Add(point.TestCaseId); } return(result.Count); }
/// <summary> /// Renames the suite. /// </summary> /// <param name="suiteId">The suite unique identifier.</param> /// <param name="newName">The new name.</param> public static void RenameSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteId, string newName) { ITestSuiteBase currentSuite = testManagementTeamProject.TestSuites.Find(suiteId); log.InfoFormat("Change Suite title from {0} to {1}, Suite Id = {2}", currentSuite.Title, newName, currentSuite.Id); currentSuite.Title = newName; testPlan.Save(); }
public void UpdateQueryConditions(ITestPlan testPlan, string testSuiteName, string replaced, string replacing) { if (string.IsNullOrWhiteSpace(testSuiteName)) { List <IDynamicTestSuite> dynamicTestSuites = new List <IDynamicTestSuite>(); ITestSuiteEntryCollection suiteCollection = testPlan.RootSuite.Entries; GetAllQueryBasedTestSuiteFromSuiteNode(suiteCollection, dynamicTestSuites); foreach (IDynamicTestSuite dynamicTestSuite in dynamicTestSuites) { UpdateQueryConditionsToSuite(dynamicTestSuite, replaced, replacing); } } else { ITestSuiteBase testSuite = GetSuites(testPlan.Name, testSuiteName) .FirstOrDefault( s => s.TestSuiteType.Equals(TestSuiteType.DynamicTestSuite)); if (testSuite == null) { throw new TestObjectNotFoundException(string.Format("Query based test suite - {0} not found", testSuiteName)); } var dynamicTestSuite = testSuite as IDynamicTestSuite; UpdateQueryConditionsToSuite(dynamicTestSuite, replaced, replacing); } }
private TestResult calculateTestResultByPlans(ITestManagementTeamProject project, ITestPlan testPlan) { var testResult = new TestResult(); testResult.Name = string.Format("{0} - {1}", testPlan.Iteration, testPlan.Name); var testSuites = new List<ITestSuiteBase>(); if (testPlan.RootSuite != null) testSuites.AddRange(GetTestSuiteRecursive(testPlan.RootSuite)); foreach (var testSuite in testSuites) { string queryForTestPointsForSpecificTestSuite = string.Format(CultureInfo.InvariantCulture, "SELECT * FROM TestPoint WHERE SuiteId = {0}", testSuite.Id); var testPoints = testPlan.QueryTestPoints(queryForTestPointsForSpecificTestSuite); foreach (var point in testPoints) { // only get the last result for the current test point // otherwise we would mix test results with different users var result = project .TestResults .ByTestId(point.TestCaseId) .LastOrDefault(testResultToFind => testResultToFind.TestPointId == point.Id); updateTestResultWithOutcome(testResult, result); } } return testResult; }
internal override void InternalExecute() { ITestPlanCollection sourcePlans = sourceTestStore.GetTestPlans(); Trace.WriteLine(string.Format("Plan to copy {0} Plans?", sourcePlans.Count), "TestPlansAndSuites"); foreach (ITestPlan sourcePlan in sourcePlans) { string newPlanName = string.Format("{0}-{1}", sourceWitStore.GetProject().Name, sourcePlan.Name); Trace.WriteLine(string.Format("Process Plan {0} - ", newPlanName), "TestPlansAndSuites"); ITestPlan targetPlan = FindTestPlan(targetTestStore, newPlanName); if (targetPlan == null) { Trace.WriteLine(string.Format(" Plan missing...creating"), "TestPlansAndSuites"); targetPlan = CreateNewTestPlanFromSource(sourcePlan, newPlanName); targetPlan.Save(); } else { Trace.WriteLine(string.Format(" Plan found"), "TestPlansAndSuites"); } if (HasChildSuits(sourcePlan.RootSuite)) { Trace.WriteLine(string.Format(" Source Plan has {0} Suites", sourcePlan.RootSuite.Entries.Count), "TestPlansAndSuites"); foreach (ITestSuiteBase sourcerSuiteChild in sourcePlan.RootSuite.SubSuites) { ProcessStaticSuite(sourcerSuiteChild, targetPlan.RootSuite, targetPlan); } // Add Test Cases ProcessChildTestCases(sourcePlan.RootSuite, targetPlan.RootSuite, targetPlan); } } }
// copied from http://automatetheplanet.com/manage-tfs-test-suites-csharp-code/ public void DeleteSuite(ITestPlan testPlan, int suiteToBeRemovedId, IStaticTestSuite parent = null) { ITestSuiteBase currentSuite = _client.TeamProject.TestSuites.Find(suiteToBeRemovedId); if (currentSuite == null) { throw new TestObjectNotFoundException(string.Format("Suite can't be found")); } // Remove the parent child relation. This is the only way to delete the suite. if (parent != null) { parent.Entries.Remove(currentSuite); } else if (currentSuite.Parent != null) { currentSuite.Parent.Entries.Remove(currentSuite); } else { // If it's initial suite, remove it from the test plan. testPlan.RootSuite.Entries.Remove(currentSuite); } // Apply changes to the suites testPlan.Save(); }
private ITestPlan CreateNewTestPlanFromSource(ITestPlan sourcePlan, string newPlanName) { ITestPlan targetPlan; targetPlan = targetTestStore.CreateTestPlan(); targetPlan.CopyPropertiesFrom(sourcePlan); targetPlan.Name = newPlanName; targetPlan.StartDate = sourcePlan.StartDate; targetPlan.EndDate = sourcePlan.EndDate; targetPlan.Description = sourcePlan.Description; if (config.PrefixProjectToNodes) { targetPlan.AreaPath = string.Format(@"{0}\{1}", engine.Target.Name, sourcePlan.AreaPath); targetPlan.Iteration = string.Format(@"{0}\{1}", engine.Target.Name, sourcePlan.Iteration); } else { var regex = new Regex(Regex.Escape(engine.Source.Name)); targetPlan.AreaPath = regex.Replace(sourcePlan.AreaPath, engine.Target.Name, 1); targetPlan.Iteration = regex.Replace(sourcePlan.Iteration, engine.Target.Name, 1); } targetPlan.ManualTestSettingsId = 0; return(targetPlan); }
private async Task <ITestResult> RunTest(ITestPlan testPlan, ITestConfiguration testConfiguration) { var stepResults = new List <IStepRunResult>(); var asyncSteps = new List <Task <IStepRunResult> >(); foreach (var testStep in testPlan.Setps) { if (stepResults.Any(x => !x.Pass) && testConfiguration.StopOnFirstError) { break; } if (testStep.CanBeRunInParallel) { Task <IStepRunResult> taskStep = this.RunStep(testStep); asyncSteps.Add(taskStep); continue; } if (asyncSteps.Any()) { IStepRunResult[] collectiveResults = await Task.WhenAll(asyncSteps); stepResults.AddRange(collectiveResults); } IStepRunResult result = await this.RunStep(testStep); stepResults.Add(result); } return(new TestResult(stepResults)); }
//Copy all Test suites from source plan to destination plan. private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan) { ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries; logger.Info("RK: found " + suites.Count + " in test plan " + sourceplan.Name); CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite); foreach (ITestSuiteEntry suite_entry in suites) { IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite; if (suite != null) { IStaticTestSuite newSuite = destinationproj.TestSuites.CreateStatic(); newSuite.Title = suite.Title; destinationplan.RootSuite.Entries.Add(newSuite); destinationplan.Save(); CopyTestCases(suite, newSuite); if (suite.Entries.Count > 0) { CopySubTestSuites(suite, newSuite); } } else if (suite_entry.TestSuite != null) { logger.Info("RK: suite entry is not static suite " + suite_entry.Title); } } }
/// <summary> /// Initializes a new instance of the <see cref="TestCase" /> class. /// </summary> /// <param name="testCaseCore">The test case core object.</param> /// <param name="testSuiteBaseCore">The test suite base core object.</param> /// <param name="initializeStatus">if set to <c>true</c> [initialize status].</param> public TestCase(ITestCase testCaseCore, ITestSuiteBase testSuiteBaseCore, ITestPlan testPlan, bool initializeStatus = true) { this.ITestCase = testCaseCore; this.ITestSuiteBase = testSuiteBaseCore; this.TestCaseId = testCaseCore.Id; this.Title = testCaseCore.Title; this.Area = testCaseCore.Area; this.Priority = (Priority)testCaseCore.Priority; if (testCaseCore.OwnerTeamFoundationId != default(Guid) && !string.IsNullOrEmpty(testCaseCore.OwnerName)) { this.TeamFoundationIdentityName = new TeamFoundationIdentityName(testCaseCore.OwnerTeamFoundationId, testCaseCore.OwnerName); } this.OwnerDisplayName = testCaseCore.OwnerName; this.TeamFoundationId = testCaseCore.OwnerTeamFoundationId; this.TestSuiteId = (testSuiteBaseCore == null) ? null : (int?)testSuiteBaseCore.Id; base.isInitialized = true; this.Id = testCaseCore.Id; this.DateCreated = testCaseCore.DateCreated; this.DateModified = testCaseCore.DateModified; this.CreatedBy = testCaseCore.WorkItem.CreatedBy; if (testSuiteBaseCore != null) { this.TestSuiteTitle = testSuiteBaseCore.Title; } if (initializeStatus) { string mostRecentResult = TestCaseManager.GetMostRecentTestCaseResult(testPlan, this.Id); this.LastExecutionOutcome = TestCaseManager.GetTestCaseExecutionType(mostRecentResult); } if (ExecutionContext.TestCaseRuns.ContainsKey(this.Id)) { this.IsRunning = "R"; } }
private Thread CreateTaskThread() { return(new Thread(() => { while (true) { try { using (new ConsoleFormatter(ConsoleColor.DarkGreen, ConsoleColor.White)) { Console.WriteLine($"Refreshing data at: {DateTime.Now.ToShortTimeString()}"); } lock (handle) { using (TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(context.ApiUrl))) { ITestManagementService service = tfs.GetService(typeof(ITestManagementService)) as ITestManagementService; ITestManagementTeamProject testProject = service.GetTeamProject(context.Project); //Can extract information about the test suite from here ITestSuiteBase testSuite = testProject.TestSuites.Find(context.SuiteId); //This is a given instance of the test suite , I.E the test plan (suites can be re-used) ITestPlan testPlan = testProject.TestPlans.Find(context.PlanId); Console.WriteLine($"Test Suite: {testSuite.Title} \n Description: {testPlan.Description} \n Last Updated: {testPlan.LastUpdated}"); testPlanDataSetFactory.Initialize(testPlan, testProject, context.ApiUrl, context.Project); } } Thread.Sleep(TimeSpan.FromMinutes(context.RefreshTime)); } catch (ThreadInterruptedException) { // This is used as a way to wake up sleeping thread. } } })); }
public static ITestRun CreateTestRun(int testId) { NetworkCredential cred = new NetworkCredential("UserName", "Password"); TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("VSTSSiteBase")); tfs.Credentials = cred; tfs.Authenticate(); tfs.EnsureAuthenticated(); ITestManagementTeamProject project = tfs.GetService <ITestManagementService>().GetTeamProject("Schwans Company"); // find the test case. ITestCase testCase = project.TestCases.Find(testId); string title = testCase.Title.ToString(); // find test plan. int planId = Int32.Parse("testPlanId"); //ConfigurationManager.AppSettings["TestPlanId"]); ITestPlan plan = project.TestPlans.Find(planId); // Create test configuration. You can reuse this instead of creating a new config everytime. ITestConfiguration config = CreateTestConfiguration(project, string.Format("My test config {0}", DateTime.Now)); // Create test points. IList <ITestPoint> testPoints = CreateTestPoints(project, plan, new List <ITestCase>() { testCase }, new IdAndName[] { new IdAndName(config.Id, config.Name) }); // Create test run using test points. ITestRun run = CreateRun(project, plan, testPoints, title); return(run); }
private void AddChildTestCases(ITestSuiteBase source, ITestSuiteBase target, ITestPlan targetPlan) { target.Refresh(); targetPlan.Refresh(); targetPlan.RefreshRootSuite(); if (CanSkipElementBecauseOfTags(source.Id)) { return; } Trace.WriteLine(string.Format(" Suite has {0} test cases", source.TestCases.Count), "TestPlansAndSuites"); List <ITestCase> tcs = new List <ITestCase>(); foreach (ITestSuiteEntry sourceTestCaseEntry in source.TestCases) { Trace.WriteLine($"Work item: {sourceTestCaseEntry.Id}"); if (CanSkipElementBecauseOfTags(sourceTestCaseEntry.Id)) { return; } Trace.WriteLine(string.Format(" Processing {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); WorkItem wi = targetWitStore.FindReflectedWorkItem(sourceTestCaseEntry.TestCase.WorkItem, me.ReflectedWorkItemIdFieldName, false); if (wi == null) { Trace.WriteLine(string.Format(" Can't find work item for Test Case. Has it been migrated? {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); break; } var exists = (from tc in target.TestCases where tc.TestCase.WorkItem.Id == wi.Id select tc).SingleOrDefault(); if (exists != null) { Trace.WriteLine(string.Format(" Test case already in suite {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } else { ITestCase targetTestCase = targetTestStore.Project.TestCases.Find(wi.Id); if (targetTestCase == null) { Trace.WriteLine(string.Format(" ERROR: Test case not found {0} : {1} - {2} ", sourceTestCaseEntry.EntryType, sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } else { tcs.Add(targetTestCase); Trace.WriteLine(string.Format(" Adding {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } } } target.TestCases.AddCases(tcs); targetPlan.Save(); Trace.WriteLine(string.Format(" SAVED {0} : {1} - {2} ", target.TestSuiteType.ToString(), target.Id, target.Title), "TestPlansAndSuites"); }
internal override void InternalExecute() { ITestPlanCollection sourcePlans = sourceTestStore.GetTestPlans(); Trace.WriteLine(string.Format("Plan to copy {0} Plans?", sourcePlans.Count), "TestPlansAndSuites"); foreach (ITestPlan sourcePlan in sourcePlans) { if (CanSkipElementBecauseOfTags(sourcePlan.Id)) { continue; } var newPlanName = config.PrefixProjectToNodes ? $"{sourceWitStore.GetProject().Name}-{sourcePlan.Name}" : $"{sourcePlan.Name}"; Trace.WriteLine($"Process Plan {newPlanName}", Name); var targetPlan = FindTestPlan(targetTestStore, newPlanName); if (targetPlan == null) { Trace.WriteLine(" Plan missing... creating", Name); targetPlan = CreateNewTestPlanFromSource(sourcePlan, newPlanName); RemoveInvalidLinks(targetPlan); targetPlan.Save(); ApplyFieldMappings(sourcePlan.Id, targetPlan.Id); AssignReflectedWorkItemId(sourcePlan.Id, targetPlan.Id); FixAssignedToValue(sourcePlan.Id, targetPlan.Id); ApplyDefaultConfigurations(sourcePlan.RootSuite, targetPlan.RootSuite); ApplyFieldMappings(sourcePlan.RootSuite.Id, targetPlan.RootSuite.Id); AssignReflectedWorkItemId(sourcePlan.RootSuite.Id, targetPlan.RootSuite.Id); FixAssignedToValue(sourcePlan.RootSuite.Id, targetPlan.RootSuite.Id); // Add Test Cases & apply configurations AddChildTestCases(sourcePlan.RootSuite, targetPlan.RootSuite, targetPlan); } else { Trace.WriteLine(" Plan already found, not creating", Name); } if (HasChildSuites(sourcePlan.RootSuite)) { Trace.WriteLine($" Source Plan has {sourcePlan.RootSuite.Entries.Count} Suites", Name); foreach (var sourceSuiteChild in sourcePlan.RootSuite.SubSuites) { ProcessTestSuite(sourceSuiteChild, targetPlan.RootSuite, targetPlan); } } targetPlan.Save(); // Load the plan again, because somehow it doesn't let me set configurations on the already loaded plan ITestPlan targetPlan2 = FindTestPlan(targetTestStore, targetPlan.Name); ApplyConfigurationsAndAssignTesters(sourcePlan.RootSuite, targetPlan2.RootSuite); } }
private static ITestPlan CreateTestPlan(ITestManagementTeamProject project, string title) { // Create a test plan. ITestPlan testPlan = project.TestPlans.Create(); testPlan.Name = title; testPlan.Save(); return(testPlan); }
/// <summary> /// Creates the test plan. /// </summary> /// <param name="tfsTeamProjectCollection">The TFS team project collection.</param> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="name">The name.</param> /// <returns></returns> public static TestPlan CreateTestPlan(TfsTeamProjectCollection tfsTeamProjectCollection, ITestManagementTeamProject testManagementTeamProject, string name) { ITestPlan newTestPlan = testManagementTeamProject.TestPlans.Create(); newTestPlan.Name = name; newTestPlan.Owner = tfsTeamProjectCollection.AuthorizedIdentity; newTestPlan.Save(); return(new TestPlan(newTestPlan)); }
/// <summary> /// Initializes a new instance of the <see cref="TfsTestPlan"/> class. /// </summary> /// <param name="testPlan">Original test plan - <see cref="ITestPlan"/>.</param> public TfsTestPlan(ITestPlan testPlan) { if (testPlan == null) { throw new ArgumentNullException("testPlan"); } OriginalTestPlan = testPlan; Id = OriginalTestPlan.Id; Name = OriginalTestPlan.Name; RootTestSuite = new TfsTestSuite(OriginalTestPlan.RootSuite, this); }
public void CreateTestCasesFromAutomatedTests(string tfsURL, string tfsProjectName, int generalAutomationPlanID) { //Connect to Project by name TfsTeamProjectCollection projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsURL)); ITestManagementTeamProject teamProject = projectCollection.GetService <ITestManagementService>().GetTeamProject(tfsProjectName); //Connect to Plan by ID ITestPlan foundPlan = teamProject.TestPlans.Find(generalAutomationPlanID); IStaticTestSuite newSuite = teamProject.TestSuites.CreateStatic(); newSuite.Title = "My Suite"; }
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(); }
public async Task <ITestResult> Run(ITestPlan testPlan, ITestConfiguration testConfiguration) { Guard.IsNotNull(testPlan, nameof(testPlan)); Guard.IsNotNull(testConfiguration, nameof(testConfiguration)); if (testPlan.Setps.IsNullOrEmpty()) { return(new TestResult("Test has no steps")); } return(await this.RunTest(testPlan, testConfiguration)); }
private static ITestRun CreateRun(ITestManagementTeamProject project, ITestPlan plan, IList <ITestPoint> points, string title) { ITestRun run = plan.CreateTestRun(false); foreach (ITestPoint tp in points) { run.AddTestPoint(tp, null); run.Title = title; } run.Save(); return(run); }
// 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); }
//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; } }
//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 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); }
public void CopyTestPlans() { int i = 1; int planCount = sourceproj.TestPlans.Query("Select * From TestPlan").Count; //delete Test Plans if any existing test plans. //foreach (ITestPlan destinationplan in destinationproj.TestPlans.Query("Select * From TestPlan")) //{ // System.Diagnostics.Debug.WriteLine("Deleting Plan - {0} : {1}", destinationplan.Id, destinationplan.Name); // destinationplan.Delete(DeleteAction.ForceDeletion); ; //} logger.Info("RK: found " + planCount + " test plans"); foreach (ITestPlan sourceplan in sourceproj.TestPlans.Query("Select * From TestPlan")) { logger.InfoFormat("RK: Plan - {0} : {1}", sourceplan.Id, sourceplan.Name); ITestPlan destinationplan = destinationproj.TestPlans.Create(); destinationplan.Name = sourceplan.Name; destinationplan.Description = sourceplan.Description; destinationplan.StartDate = sourceplan.StartDate; destinationplan.EndDate = sourceplan.EndDate; destinationplan.State = sourceplan.State; // destinationplan.Owner // destinationplan.testpo destinationplan.Save(); //drill down to root test suites. if (sourceplan.RootSuite != null && sourceplan.RootSuite.Entries.Count > 0) { CopyTestSuites(sourceplan, destinationplan); } else { logger.Info("RK: No test suites found for plan " + sourceplan.Name); } destinationplan.Save(); progressBar.Dispatcher.BeginInvoke(new Action(delegate() { float progress = (float)i / (float)planCount; progressBar.Value = ((float)i / (float)planCount) * 100; })); i++; } }
public void CopyTestPlans() { int i = 1; int planCount = sourceproj.TestPlans.Query("Select * From TestPlan").Count; //delete Test Plans if any existing test plans. //foreach (ITestPlan destinationplan in destinationproj.TestPlans.Query("Select * From TestPlan")) //{ // System.Diagnostics.Debug.WriteLine("Deleting Plan - {0} : {1}", destinationplan.Id, destinationplan.Name); // destinationplan.Delete(DeleteAction.ForceDeletion); ; //} foreach (ITestPlan sourceplan in sourceproj.TestPlans.Query("Select * From TestPlan")) { if (!sourceplan.Name.Equals("CLEF Testing")) { continue; } System.Diagnostics.Debug.WriteLine("Plan - {0} : {1}", sourceplan.Id, sourceplan.Name); ITestPlan destinationplan = destinationproj.TestPlans.Create(); destinationplan.Name = "CLEF Testing V1.0"; destinationplan.Description = sourceplan.Description; destinationplan.StartDate = sourceplan.StartDate; destinationplan.EndDate = sourceplan.EndDate; destinationplan.State = sourceplan.State; destinationplan.Owner = UserID; destinationplan.Save(); //drill down to root test suites. if (sourceplan.RootSuite != null && sourceplan.RootSuite.Entries.Count > 0) { CopyTestSuites(sourceplan, destinationplan); } destinationplan.Save(); progressBar.Dispatcher.BeginInvoke(new Action(delegate() { float progress = (float)i / (float)planCount; progressBar.Value = ((float)i / (float)planCount) * 100; })); i++; } }
/// <summary> /// Copies a test plan. /// </summary> /// <param name="destinationProject">The destination project.</param> /// <param name="sourceTestPlan">The source test plan.</param> public static string CopyTestPlan(ITestManagementTeamProject destinationProject, ITestPlan sourceTestPlan) { string results = "Copying Test Plan " + sourceTestPlan.Name + Environment.NewLine; CreateAndCollectInfoForDestinationAreaAndIterations(destinationProject, sourceTestPlan.Project.WitProject); ITestPlan destinationTestPlan = destinationProject.TestPlans.Create(); destinationTestPlan.Name = sourceTestPlan.Name; destinationTestPlan.StartDate = sourceTestPlan.StartDate; destinationTestPlan.EndDate = sourceTestPlan.EndDate; destinationTestPlan.Save(); results += CopyTestCases(sourceTestPlan.RootSuite, destinationTestPlan.RootSuite); results += CopyTestSuites(sourceTestPlan, destinationTestPlan); return results; }
/// <summary> /// Gets all test cases from all test suites.d /// </summary> /// <param name="testPlan">The test plan.</param> /// <param name="suiteEntries">The test suite collection.</param> /// <param name="alreadyCheckedSuitesIds">The already checked suites ids.</param> /// <returns> /// list with all test cases /// </returns> public static List<TestCase> GetAllTestCasesFromSuiteCollection(ITestPlan testPlan, ITestSuiteCollection suiteEntries, List<int> alreadyCheckedSuitesIds = null) { if (alreadyCheckedSuitesIds == null) { alreadyCheckedSuitesIds = new List<int>(); } List<TestCase> testCases = new List<TestCase>(); foreach (ITestSuiteBase currentSuite in suiteEntries) { if (currentSuite != null && !alreadyCheckedSuitesIds.Contains(currentSuite.Id)) { alreadyCheckedSuitesIds.Add(currentSuite.Id); currentSuite.Refresh(); foreach (var currentTestCase in currentSuite.TestCases) { TestCase testCaseToAdd = new TestCase(currentTestCase.TestCase, currentSuite, testPlan); if (!testCases.Contains(testCaseToAdd)) { testCases.Add(testCaseToAdd); } } if (currentSuite.TestSuiteType == TestSuiteType.StaticTestSuite) { IStaticTestSuite staticTestSuite = currentSuite as IStaticTestSuite; if (staticTestSuite != null && (staticTestSuite.SubSuites.Count > 0)) { List<TestCase> testCasesInternal = GetAllTestCasesFromSuiteCollection(testPlan, staticTestSuite.SubSuites, alreadyCheckedSuitesIds); foreach (var currentTestCase in testCasesInternal) { if (!testCases.Contains(currentTestCase)) { testCases.Add(currentTestCase); } } } } } } return testCases; }
/// <summary> /// Gets all test cases in current test plan. /// </summary> /// <param name="initializeTestCaseStatus">if set to <c>true</c> [initialize test case status].</param> /// <returns> /// list of all test cases /// </returns> public static List<TestCase> GetAllTestCasesInTestPlan(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, bool initializeTestCaseStatus = true) { testPlan.Refresh(); List<TestCase> testCasesList; testCasesList = new List<TestCase>(); string fullQuery = String.Format(AllTestCasesInTeamProjectQueryExpression, testManagementTeamProject.TeamProjectName); IEnumerable<ITestCase> allTestCases = testManagementTeamProject.TestCases.Query(fullQuery); foreach (var currentTestCase in allTestCases) { TestCase testCaseToAdd = new TestCase(currentTestCase, currentTestCase.TestSuiteEntry.ParentTestSuite, testPlan, initializeTestCaseStatus); if (!testCasesList.Contains(testCaseToAdd)) { testCasesList.Add(testCaseToAdd); } } return testCasesList; }
/// <summary> /// Saves the specified test case. /// </summary> /// <param name="sourceTestCase">The test case.</param> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="createNew">should be saved as new test case.</param> /// <param name="suiteId">The suite identifier.</param> /// <param name="testSteps">The test steps.</param> /// <param name="shouldAssignArea">if set to <c>true</c> [should assign area].</param> /// <param name="isMigration">if set to <c>true</c> [is migration].</param> /// <returns> /// the saved test case /// </returns> public static TestCase Save( this TestCase sourceTestCase, ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, bool createNew, int? suiteId, ICollection<TestStep> testSteps, bool shouldAssignArea = true, bool isMigration = false) { TestCase currentTestCase = sourceTestCase; if (createNew) { ITestCase testCaseCore = testManagementTeamProject.TestCases.Create(); currentTestCase = new TestCase(testCaseCore, sourceTestCase.ITestSuiteBase, testPlan); } if (shouldAssignArea) { currentTestCase.ITestCase.Area = sourceTestCase.Area; } currentTestCase.ITestCase.Description = sourceTestCase.ITestCase.Description; currentTestCase.ITestCase.Title = sourceTestCase.Title; currentTestCase.ITestCase.Priority = (int)sourceTestCase.Priority; currentTestCase.ITestCase.Actions.Clear(); currentTestCase.ITestCase.Owner = testManagementTeamProject.TfsIdentityStore.FindByTeamFoundationId(sourceTestCase.TeamFoundationId); if (sourceTestCase.ITestCase.Implementation != null && isMigration) { currentTestCase.ITestCase.Implementation = sourceTestCase.ITestCase.Implementation; } List<Guid> addedSharedStepGuids = new List<Guid>(); foreach (TestStep currentStep in testSteps) { if (currentStep.IsShared && !addedSharedStepGuids.Contains(currentStep.TestStepGuid)) { ISharedStep sharedStepCore = testManagementTeamProject.SharedSteps.Find(currentStep.SharedStepId); ISharedStepReference sharedStepReferenceCore = currentTestCase.ITestCase.CreateSharedStepReference(); sharedStepReferenceCore.SharedStepId = sharedStepCore.Id; currentTestCase.ITestCase.Actions.Add(sharedStepReferenceCore); addedSharedStepGuids.Add(currentStep.TestStepGuid); } else if (!currentStep.IsShared) { ITestStep testStepCore = currentTestCase.ITestCase.CreateTestStep(); testStepCore.Title = currentStep.ActionTitle; testStepCore.ExpectedResult = currentStep.ActionExpectedResult; currentTestCase.ITestCase.Actions.Add(testStepCore); } } if (suiteId != null) { var newSuite = TestSuiteManager.GetTestSuiteById(testManagementTeamProject, testPlan, (int)suiteId); sourceTestCase.ITestSuiteBase = newSuite; } currentTestCase.ITestCase.Flush(); currentTestCase.ITestCase.Save(); if (suiteId != null) { SetTestCaseSuite(testManagementTeamProject, testPlan, (int)suiteId, currentTestCase); } currentTestCase.ITestCase.Flush(); currentTestCase.ITestCase.Save(); return currentTestCase; }
/// <summary> /// Pastes the suite to parent suite. /// </summary> /// <param name="parentSuite">The parent suite.</param> /// <param name="clipboardSuite">The clipboard suite.</param> public void CopyPasteSuiteToParentSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, Suite parentSuite, Suite clipboardSuite) { try { TestSuiteManager.PasteSuiteToParent(testManagementTeamProject, testPlan, parentSuite.Id, clipboardSuite.Id, ClipBoardCommand.Copy); } catch (TestManagementValidationException ex) { log.Error(ex); if (ex.Message.Equals("This item has already been added. A test suite cannot contain a duplicate test case or test suite.")) { ModernDialog.ShowMessage(ex.Message, "Warrning!", MessageBoxButton.OK); return; } } Suite suiteToBePasted = (Suite)clipboardSuite.Clone(); suiteToBePasted.Parent = parentSuite; parentSuite.SubSuites.Add(suiteToBePasted); parentSuite.IsSelected = true; parentSuite.IsNodeExpanded = true; }
/// <summary> /// Gets all test case from suite. /// </summary> /// <param name="testPlan">The test plan.</param> /// <param name="suiteId">The suite unique identifier.</param> /// <param name="includeExecutionStatus">if set to <c>true</c> [include execution status].</param> /// <returns> /// list of all test cases in the list /// </returns> 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; }
/// <summary> /// Sets the test case suite. /// </summary> /// <param name="suiteId">The suite unique identifier.</param> /// <param name="testCase">The test case.</param> private static void SetTestCaseSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteId, TestCase testCase) { var newSuite = TestSuiteManager.GetTestSuiteById(testManagementTeamProject, testPlan, suiteId); if (newSuite != null) { newSuite.AddTestCase(testCase.ITestCase); testCase.ITestSuiteBase = newSuite; } }
/// <summary> /// Initializes a new instance of the <see cref="TestPlan"/> class. /// </summary> /// <param name="testPlanCore">The test plan core.</param> public TestPlan(ITestPlan testPlanCore) { this.Id = testPlanCore.Id; this.Name = testPlanCore.Name; this.OwnerDisplayName = testPlanCore.Owner.DisplayName; }
void GetTestSuites_Plan(int ID) { TP = _testproject.TestPlans.Find(ID); if (TP != null) { if(TP.RootSuite != null) { TreeViewItem root = new TreeViewItem(); root.Header = TP.RootSuite.Title.ToString() + " <ID: " + TP.RootSuite.Id.ToString() + " >"; treeView_suite.Items.Add(root); GetSuiteEntries(TP.RootSuite.SubSuites, root); } } }
private void DeleteTestSuitesFrom(ITestPlan testPlan) { Console.WriteLine("Cleaning up '{0}'", testPlan.RootSuite.Title); Console.WriteLine("Completed"); Console.WriteLine(); var rootSuite = testPlan.RootSuite; var testSuites = rootSuite.Entries.Select(e => e.TestSuite).OfType<IStaticTestSuite>().ToList(); foreach (var testSuit in testSuites) { rootSuite.Entries.Remove(testSuit); } testPlan.Save(); }
//Copy all Test suites from source plan to destination plan. private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan) { ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries; CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite); foreach (ITestSuiteEntry suite_entry in suites) { IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite; if (suite != null) { IStaticTestSuite newSuite = destinationproj.TestSuites.CreateStatic(); newSuite.Title = suite.Title; destinationplan.RootSuite.Entries.Add(newSuite); destinationplan.Save(); CopyTestCases(suite, newSuite); if (suite.Entries.Count > 0) CopySubTestSuites(suite, newSuite); } } }
/// <summary> /// Gets the test suite core object by id. /// </summary> /// <param name="suiteId">The suite unique identifier.</param> /// <returns>test suite core object</returns> public static ITestSuiteBase GetTestSuiteById(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteId) { ITestSuiteBase testSuiteBase = null; if (suiteId > 0) { // If it's old test case testSuiteBase = testManagementTeamProject.TestSuites.Find(suiteId); } else { // If the test case is new it will be added to root suite of the test plan testSuiteBase = testPlan.RootSuite; } return testSuiteBase; }
/// <summary> /// Pastes the suite to parent. /// </summary> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="parentSuiteId">The parent suite unique identifier.</param> /// <param name="suiteToAddId">The suite automatic add unique identifier.</param> /// <param name="clipBoardCommand">The clip board command.</param> /// <exception cref="System.ArgumentException">The requirments based suites cannot have child suites!</exception> public static void PasteSuiteToParent(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int parentSuiteId, int suiteToAddId, ClipBoardCommand clipBoardCommand) { ITestSuiteBase parentSuite = null; ITestSuiteBase suiteToAdd = null; try { parentSuite = testManagementTeamProject.TestSuites.Find(parentSuiteId); } catch (TestManagementValidationException ex) { log.Error(ex); } try { suiteToAdd = testManagementTeamProject.TestSuites.Find(suiteToAddId); } catch (TestManagementValidationException ex) { log.Error(ex); } IStaticTestSuite oldParent = suiteToAdd.Parent; if (parentSuite != null && parentSuite is IRequirementTestSuite) { throw new ArgumentException("The requirments based suites cannot have child suites!"); } if (parentSuite != null && parentSuite is IStaticTestSuite && parentSuiteId != -1) { IStaticTestSuite parentSuiteStatic = parentSuite as IStaticTestSuite; parentSuiteStatic.Entries.Add(suiteToAdd); log.InfoFormat("Add child suite to suite with Title= {0}, Id = {1}, child suite title= {2}, id= {3}", parentSuite.Title, parentSuite.Id, suiteToAdd.Title, suiteToAdd.Id); } else { testPlan.RootSuite.Entries.Add(suiteToAdd); } if (clipBoardCommand.Equals(ClipBoardCommand.Cut)) { DeleteSuite(testManagementTeamProject, testPlan, suiteToAddId, oldParent); } testPlan.Save(); }
/// <summary> /// Adds the child suite. /// </summary> /// <param name="parentSuiteId">The parent suite unique identifier.</param> /// <param name="title">The title.</param> /// <param name="canBeAdded">if set to <c>true</c> [can be added].</param> /// <returns> /// new suite unique identifier. /// </returns> public static int AddChildSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int parentSuiteId, string title, out bool canBeAdded) { ITestSuiteBase parentSuite = null; if (parentSuiteId != -1) { parentSuite = testManagementTeamProject.TestSuites.Find(parentSuiteId); } if (parentSuite is IRequirementTestSuite) { canBeAdded = false; return 0; } IStaticTestSuite staticSuite = testManagementTeamProject.TestSuites.CreateStatic(); canBeAdded = true; staticSuite.Title = title; if (parentSuite != null && parentSuite is IStaticTestSuite && parentSuiteId != -1) { IStaticTestSuite parentSuiteStatic = parentSuite as IStaticTestSuite; parentSuiteStatic.Entries.Add(staticSuite); log.InfoFormat("Add child suite to suite with Title= {0}, Id = {1}, child suite title= {2}", parentSuite.Title, parentSuite.Id, title); } else { testPlan.RootSuite.Entries.Add(staticSuite); log.InfoFormat("Add child suite with title= {0} to test plan", title); } testPlan.Save(); return staticSuite.Id; }
/// <summary> /// Cuts the paste suite to parent suite. /// </summary> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="parentSuite">The parent suite.</param> /// <param name="clipboardSuite">The clipboard suite.</param> public void CutPasteSuiteToParentSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, Suite parentSuite, Suite clipboardSuite) { TestSuiteManager.PasteSuiteToParent(testManagementTeamProject, testPlan, parentSuite.Id, clipboardSuite.Id, ClipBoardCommand.Cut); if (clipboardSuite.Parent != null) { this.DeleteSuiteObservableCollection(this.Suites, clipboardSuite.Id); } Suite suiteToBePasted = (Suite)clipboardSuite.Clone(); suiteToBePasted.Parent = parentSuite; parentSuite.SubSuites.Add(suiteToBePasted); parentSuite.IsSelected = true; parentSuite.IsNodeExpanded = true; System.Windows.Clipboard.Clear(); }
/// <summary> /// Finds all reference test cases for specific shared step. /// </summary> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="sharedStepId">The shared step unique identifier.</param> /// <returns></returns> public static List<TestCase> FindAllReferenceTestCasesForShareStep(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int sharedStepId) { List<TestCase> filteredTestCases = new List<TestCase>(); List<TestCase> allTestCases = GetAllTestCasesInTestPlan(testManagementTeamProject, testPlan); foreach (var currentTestCase in allTestCases) { foreach (var currentAction in currentTestCase.ITestCase.Actions) { if (currentAction is ISharedStepReference) { ISharedStepReference currentSharedStepReference = currentAction as ISharedStepReference; if (currentSharedStepReference.SharedStepId.Equals(sharedStepId)) { filteredTestCases.Add(currentTestCase); break; } } } } return filteredTestCases; }
/// <summary> /// Deletes the suite. /// </summary> /// <param name="suiteToBeRemovedId">The suite to be removed unique identifier.</param> /// <param name="parent">The parent.</param> /// <exception cref="System.ArgumentException">The root suite cannot be deleted!</exception> public static void DeleteSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteToBeRemovedId, IStaticTestSuite parent = null) { // If it's root suite throw exception if (suiteToBeRemovedId == -1) { throw new ArgumentException("The root suite cannot be deleted!"); } ITestSuiteBase currentSuite = testManagementTeamProject.TestSuites.Find(suiteToBeRemovedId); // Remove the parent child relation. This is the only way to delete the suite. if (parent != null) { log.InfoFormat("Remove suite Title= \"{0}\", id= \"{1}\" from suite Title= \"{2}\", id= \"{3}\"", currentSuite.Title, currentSuite.Id, parent.Title, parent.Id); parent.Entries.Remove(currentSuite); } else if (currentSuite.Parent != null) { log.InfoFormat("Remove suite Title= \"{0}\", id= \"{1}\" from suite Title= \"{2}\", id= \"{3}\"", currentSuite.Title, currentSuite.Id, currentSuite.Parent.Title, currentSuite.Parent.Id); currentSuite.Parent.Entries.Remove(currentSuite); } else { // If it's initial suite, remove it from the test plan. testPlan.RootSuite.Entries.Remove(currentSuite); log.Info("Remove suite Title= \"{0}\", id= \"{1}\" from test plan."); } // Apply changes to the suites testPlan.Save(); }
/// <summary> /// Adds the test cases without suites. /// </summary> /// <param name="testCasesList">The test cases list.</param> public static void AddTestCasesWithoutSuites(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, List<TestCase> testCasesList) { testPlan.Refresh(); string fullQuery = String.Format(AllTestCasesInTeamProjectQueryExpression, testManagementTeamProject.TeamProjectName); IEnumerable<ITestCase> allTestCases = testManagementTeamProject.TestCases.Query(fullQuery); foreach (var currentTestCase in allTestCases) { TestCase testCaseToAdd = new TestCase(currentTestCase, null, ExecutionContext.Preferences.TestPlan); if (!testCasesList.Contains(testCaseToAdd)) { testCasesList.Add(testCaseToAdd); } } }
/// <summary> /// Gets the latest execution times. /// </summary> /// <param name="project">The project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="testCaseId">The test case identifier.</param> /// <returns> /// latest execution times /// </returns> public static List<TestCaseRunResult> GetLatestExecutionTimes(ITestManagementTeamProject project, ITestPlan testPlan, int testCaseId) { List<TestCaseRunResult> executionTimes = new List<TestCaseRunResult>(); var testPoints = TestPointManager.GetTestPointsByTestCaseId(testPlan, testCaseId); List<TestCaseResultIdentifier> alreadyAddedRuns = new List<TestCaseResultIdentifier>(); if (testPoints != null && testPoints.Count > 0) { foreach (ITestPoint currentTestPoint in testPoints) { if (currentTestPoint.History != null) { foreach (var currentHistoryTestPoint in currentTestPoint.History) { if (currentHistoryTestPoint != null && currentHistoryTestPoint.MostRecentResultId != 0 && currentHistoryTestPoint.MostRecentResultId != 0 && currentHistoryTestPoint.MostRecentResultOutcome.Equals(TestOutcome.Passed)) { ITestCaseResult testRun = project.TestResults.Find(currentHistoryTestPoint.MostRecentRunId, currentHistoryTestPoint.MostRecentResultId); if (testRun.Duration.Ticks > 0 && !alreadyAddedRuns.Contains(testRun.Id)) { executionTimes.Add(new TestCaseRunResult( testRun.DateStarted, testRun.DateCompleted, testRun.Duration, testRun.RunByName)); alreadyAddedRuns.Add(testRun.Id); } } } } } } return executionTimes; }
/// <summary> /// Gets the most recent test case result. /// </summary> /// <param name="testPlan">The test plan.</param> /// <param name="testCaseId">The test case unique identifier.</param> /// <returns></returns> public static string GetMostRecentTestCaseResult(ITestPlan testPlan, int testCaseId) { var testPoints = TestPointManager.GetTestPointsByTestCaseId(testPlan, testCaseId); ITestPoint lastTestPoint = null; if (testPoints.Count > 0) { lastTestPoint = testPoints.Last(); } string mostRecentResult = "Active"; ITestCaseResult lastTestCaseResult = null; if (lastTestPoint != null) { lastTestCaseResult = lastTestPoint.MostRecentResult; } if (lastTestCaseResult != null) { mostRecentResult = lastTestCaseResult.Outcome.ToString(); } return mostRecentResult; }
/// <summary> /// Sets the new execution outcome. /// </summary> /// <param name="currentTestCase">The current test case.</param> /// <param name="testPlan">The test plan.</param> /// <param name="newExecutionOutcome">The new execution outcome.</param> /// <param name="comment">The comment.</param> /// <param name="testCaseRuns">The test case runs.</param> public static void SetNewExecutionOutcome(this TestCase currentTestCase, ITestPlan testPlan, TestCaseExecutionType newExecutionOutcome, string comment, Dictionary<int, TestCaseRun> testCaseRuns) { if (currentTestCase.ITestCase.Owner == null) { return; } var testPoints = testPlan.QueryTestPoints(string.Format("SELECT * FROM TestPoint WHERE TestCaseId = {0} ", currentTestCase.Id)); var testRun = testPlan.CreateTestRun(false); currentTestCase.IsRunning = string.Empty; DateTime startedDate = DateTime.Now; DateTime lastStartedDate = DateTime.Now; DateTime endDate = DateTime.Now; TimeSpan durationBeforePauses = new TimeSpan(); if (testCaseRuns.ContainsKey(currentTestCase.Id)) { lastStartedDate = testCaseRuns[currentTestCase.Id].LastStartedTime; startedDate = testCaseRuns[currentTestCase.Id].StartTime; durationBeforePauses = testCaseRuns[currentTestCase.Id].Duration; testCaseRuns.Remove(currentTestCase.Id); } testRun.DateStarted = startedDate; testRun.AddTestPoint(testPoints.Last(), ExecutionContext.TestManagementTeamProject.TestManagementService.AuthorizedIdentity); TimeSpan totalDuration = new TimeSpan((DateTime.Now - lastStartedDate).Ticks + durationBeforePauses.Ticks); testRun.DateCompleted = endDate; testRun.Save(); var result = testRun.QueryResults()[0]; result.Owner = ExecutionContext.TestManagementTeamProject.TestManagementService.AuthorizedIdentity; result.RunBy = ExecutionContext.TestManagementTeamProject.TestManagementService.AuthorizedIdentity; result.State = TestResultState.Completed; result.DateStarted = startedDate; result.Duration = totalDuration; result.DateCompleted = endDate; result.Comment = comment; switch (newExecutionOutcome) { case TestCaseExecutionType.Active: result.Outcome = TestOutcome.None; result.Duration = new TimeSpan(); break; case TestCaseExecutionType.Passed: result.Outcome = TestOutcome.Passed; break; case TestCaseExecutionType.Failed: result.Outcome = TestOutcome.Failed; break; case TestCaseExecutionType.Blocked: result.Outcome = TestOutcome.Blocked; break; } result.Save(); }
/// <summary> /// Removes the specified test case from the test suite. /// </summary> /// <param name="testPlan">The test plan.</param> /// <param name="testCaseToRemove">The test case to be removed.</param> public static void RemoveTestCase(ITestPlan testPlan, ITestCase testCaseToRemove) { RemoveTestCaseInternal(testCaseToRemove, testPlan.RootSuite.SubSuites); }
/// <summary> /// Removes the suite internal. /// </summary> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> private void RemoveSuiteInternal(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan) { int selectedSuiteId = RegistryManager.GetSelectedSuiteId(); try { if (ModernDialog.ShowMessage("If you delete this test suite, you will also delete all test suites that are children of this test suite!", "Delete this test suite?", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { TestSuiteManager.DeleteSuite(testManagementTeamProject, testPlan, selectedSuiteId); this.TestCasesInitialViewModel.DeleteSuiteObservableCollection(this.TestCasesInitialViewModel.Suites, selectedSuiteId); } } catch (ArgumentException) { ModernDialog.ShowMessage("The root suite cannot be deleted!", "Warrning!", MessageBoxButton.OK); } }
/// <summary> /// Copies test suites located at the root of a test plan. /// </summary> /// <param name="sourceTestPlan">The source test plan.</param> /// <param name="destinationTestPlan">The destination test plan.</param> private static string CopyTestSuites(ITestPlan sourceTestPlan, ITestPlan destinationTestPlan) { string results = string.Empty; foreach (IStaticTestSuite sourceTestSuite in sourceTestPlan.RootSuite.SubSuites) { IStaticTestSuite destinationTestSuite = destinationTestPlan.Project.TestSuites.CreateStatic(); destinationTestSuite.Title = sourceTestSuite.Title; destinationTestSuite.SetDefaultConfigurations(GetDefaultConfigurationCollection(destinationTestPlan.Project)); destinationTestPlan.RootSuite.Entries.Add(destinationTestSuite); destinationTestPlan.Save(); results += CopyTestCases(sourceTestSuite, destinationTestSuite); if (sourceTestSuite.Entries.Count > 0) { results += CopyTestSuites(sourceTestSuite, destinationTestSuite); } } return results; }
/// <summary> /// Gets the most recent execution comment. /// </summary> /// <param name="testPlan">The test plan.</param> /// <param name="testCaseId">The test case unique identifier.</param> /// <returns></returns> public static string GetMostRecentExecutionComment(ITestPlan testPlan, int testCaseId) { var testPoints = TestPointManager.GetTestPointsByTestCaseId(testPlan, testCaseId); ITestPoint lastTestPoint = null; if (testPoints.Count > 0) { lastTestPoint = testPoints.Last(); } string mostRecentExecutionComment = String.Empty; if (lastTestPoint != null && lastTestPoint.MostRecentResult != null && !String.IsNullOrEmpty(lastTestPoint.MostRecentResult.Comment)) { mostRecentExecutionComment = lastTestPoint.MostRecentResult.Comment; } return mostRecentExecutionComment; }
/// <summary> /// Gets all test suites from the current test plan. /// </summary> /// <returns>list of all test suites</returns> public static List<ITestSuiteBase> GetAllTestSuitesInTestPlan(ITestPlan testPlan) { List<ITestSuiteBase> testSuites = GetAllTestSuites(testPlan.RootSuite.SubSuites); return testSuites; }
/// <summary> /// Pastes the test cases to suite. /// </summary> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="suiteToAddInId">The suite automatic add information unique identifier.</param> /// <param name="clipBoardTestCase">The clip board test case.</param> /// <exception cref="System.ArgumentException">New test cases cannot be added to requirement based suites!</exception> public static void PasteTestCasesToSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteToAddInId, ClipBoardTestCase clipBoardTestCase) { ITestSuiteBase suiteToAddIn = testManagementTeamProject.TestSuites.Find(suiteToAddInId); if (suiteToAddIn is IRequirementTestSuite) { throw new ArgumentException("New test cases cannot be added to requirement based suites!"); } IStaticTestSuite suiteToAddInStatic = suiteToAddIn as IStaticTestSuite; ITestSuiteBase oldSuite; List<TestCase> allTestCasesInPlan = null; if (clipBoardTestCase.TestCases[0].TestSuiteId != null) { oldSuite = testManagementTeamProject.TestSuites.Find((int)clipBoardTestCase.TestCases[0].TestSuiteId); } else { oldSuite = null; } foreach (TestCase currentTestCase in clipBoardTestCase.TestCases) { ITestCase testCaseCore = null; if (oldSuite is IRequirementTestSuite) { IRequirementTestSuite suite = oldSuite as IRequirementTestSuite; testCaseCore = suite.TestCases.Where(x => x.TestCase != null && x.TestCase.Id.Equals(currentTestCase.TestCaseId)).FirstOrDefault().TestCase; } else if (oldSuite is IStaticTestSuite) { IStaticTestSuite suite = oldSuite as IStaticTestSuite; testCaseCore = suite.Entries.Where(x => x.TestCase != null && x.TestCase.Id.Equals(currentTestCase.TestCaseId)).FirstOrDefault().TestCase; } else if (oldSuite == null) { if (allTestCasesInPlan == null) { allTestCasesInPlan = TestCaseManager.GetAllTestCasesInTestPlan(testManagementTeamProject, testPlan); } testCaseCore = allTestCasesInPlan.Where(t => t.TestCaseId.Equals(currentTestCase.TestCaseId)).FirstOrDefault().ITestCase; } if (!suiteToAddInStatic.Entries.Contains(testCaseCore)) { suiteToAddInStatic.Entries.Add(testCaseCore); } if (clipBoardTestCase.ClipBoardCommand.Equals(ClipBoardCommand.Cut)) { if (oldSuite is IStaticTestSuite) { IStaticTestSuite suite = oldSuite as IStaticTestSuite; suite.Entries.Remove(testCaseCore); } } } testPlan.Save(); }