From 08edb6e6e0644ebd20c426e6c5c547eefcce2c68 Mon Sep 17 00:00:00 2001 From: Kathan Sanghavi <52504721+KathanS@users.noreply.github.com> Date: Tue, 24 Dec 2024 11:56:12 +0530 Subject: [PATCH] Handle manual test cases associated with same automated tests (#5064) * make duplicated automated tests with different manual test case available. * nit. --- .../TestResults/TestDataPublisher.cs | 25 +++++--- .../TestResults/Utils/TestResultUtils.cs | 57 +++++++++++++++++++ 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/Agent.Worker/TestResults/TestDataPublisher.cs b/src/Agent.Worker/TestResults/TestDataPublisher.cs index df83652f00..5d483e3837 100644 --- a/src/Agent.Worker/TestResults/TestDataPublisher.cs +++ b/src/Agent.Worker/TestResults/TestDataPublisher.cs @@ -153,6 +153,7 @@ public void InitializePublisher(IExecutionContext context, string projectName, V for (testRunDataIterator = 0; testRunDataIterator < testRunData.Count; testRunDataIterator++) { + var testResultsUpdated = new List(); for (testResultDataIterator = 0; testResultDataIterator < testRunData[testRunDataIterator].TestResults.Count; testResultDataIterator++) { var testResultFQN = testRunData[testRunDataIterator].TestResults[testResultDataIterator].AutomatedTestStorage + @@ -160,17 +161,23 @@ public void InitializePublisher(IExecutionContext context, string projectName, V if (testResultByFQN.TryGetValue(testResultFQN, out List inputs)) { - testRunData[testRunDataIterator].TestResults[testResultDataIterator].TestPoint = inputs[0].TestPoint; - testRunData[testRunDataIterator].TestResults[testResultDataIterator].TestCaseTitle = inputs[0].TestCaseTitle; - testRunData[testRunDataIterator].TestResults[testResultDataIterator].Configuration = inputs[0].Configuration; - testRunData[testRunDataIterator].TestResults[testResultDataIterator].TestCase = inputs[0].TestCase; - testRunData[testRunDataIterator].TestResults[testResultDataIterator].Owner = inputs[0].Owner; - testRunData[testRunDataIterator].TestResults[testResultDataIterator].State = "5"; - testRunData[testRunDataIterator].TestResults[testResultDataIterator].TestCaseRevision = inputs[0].TestCaseRevision; - - testResultByFQN[testResultFQN].RemoveAt(0); + foreach (var input in inputs) + { + var testCaseResultDataUpdated = TestResultUtils.CloneTestCaseResultData(testRunData[testRunDataIterator].TestResults[testResultDataIterator]); + + testCaseResultDataUpdated.TestPoint = input.TestPoint; + testCaseResultDataUpdated.TestCaseTitle = input.TestCaseTitle; + testCaseResultDataUpdated.Configuration = input.Configuration; + testCaseResultDataUpdated.TestCase = input.TestCase; + testCaseResultDataUpdated.Owner = input.Owner; + testCaseResultDataUpdated.State = "5"; + testCaseResultDataUpdated.TestCaseRevision = input.TestCaseRevision; + + testResultsUpdated.Add(testCaseResultDataUpdated); + } } } + testRunData[testRunDataIterator].TestResults = testResultsUpdated; } } diff --git a/src/Agent.Worker/TestResults/Utils/TestResultUtils.cs b/src/Agent.Worker/TestResults/Utils/TestResultUtils.cs index 5794409a42..cc49b015df 100644 --- a/src/Agent.Worker/TestResults/Utils/TestResultUtils.cs +++ b/src/Agent.Worker/TestResults/Utils/TestResultUtils.cs @@ -5,6 +5,8 @@ using System; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; +using Microsoft.TeamFoundation.TestClient.PublishTestResults; +using System.Linq; namespace Microsoft.VisualStudio.Services.Agent.Worker.TestResults.Utils { @@ -32,6 +34,61 @@ public static void StoreTestRunSummaryInEnvVar(IExecutionContext executionContex } } + public static TestCaseResultData CloneTestCaseResultData(TestCaseResultData original) + { + return new TestCaseResultData + { + Id = original.Id, + Comment = original.Comment, + Configuration = original.Configuration, + Project = original.Project, + StartedDate = original.StartedDate, + CompletedDate = original.CompletedDate, + DurationInMs = original.DurationInMs, + Outcome = original.Outcome, + Revision = original.Revision, + State = original.State, + TestCase = original.TestCase, + TestPoint = original.TestPoint, + TestRun = original.TestRun, + ResolutionStateId = original.ResolutionStateId, + ResolutionState = original.ResolutionState, + LastUpdatedDate = original.LastUpdatedDate, + Priority = original.Priority, + ComputerName = original.ComputerName, + ResetCount = original.ResetCount, + Build = original.Build, + Release = original.Release, + ErrorMessage = original.ErrorMessage, + CreatedDate = original.CreatedDate, + IterationDetails = original.IterationDetails?.ToList(), + AssociatedBugs = original.AssociatedBugs?.ToList(), + Url = original.Url, + FailureType = original.FailureType, + AutomatedTestName = original.AutomatedTestName, + AutomatedTestStorage = original.AutomatedTestStorage, + AutomatedTestType = original.AutomatedTestType, + AutomatedTestTypeId = original.AutomatedTestTypeId, + AutomatedTestId = original.AutomatedTestId, + Area = original.Area, + TestCaseTitle = original.TestCaseTitle, + StackTrace = original.StackTrace, + CustomFields = original.CustomFields?.ToList(), + BuildReference = original.BuildReference, + ReleaseReference = original.ReleaseReference, + TestPlan = original.TestPlan, + TestSuite = original.TestSuite, + TestCaseReferenceId = original.TestCaseReferenceId, + Owner = original.Owner, + RunBy = original.RunBy, + LastUpdatedBy = original.LastUpdatedBy, + ResultGroupType = original.ResultGroupType, + TestCaseRevision = original.TestCaseRevision, + TestCaseSubResultData = original.TestCaseSubResultData?.ToList(), + AttachmentData = original.AttachmentData + }; + } + private static string GetEvidenceStoreMetadata(IExecutionContext executionContext, TestRunSummary testRunSummary, string testRunner, string name, string description) { string evidenceStoreMetadataString = string.Empty;