/// <summary> /// Returns the QToolsCommon.TestResult object created from rockSteady TestResult. /// </summary> /// <param name="rockSteadyTestResult"> rock steady test result</param> /// <param name="testElement"> testElement of that test</param> /// <param name="testOutcome"> Test outcome </param> /// <param name="testRun"> test run object </param> /// <returns> TestResult object </returns> private static TrxObjectModel.UnitTestResult GetQToolsTestResultFromTestResult( ObjectModel.TestResult rockSteadyTestResult, TrxObjectModel.UnitTestElement testElement, TrxObjectModel.TestOutcome testOutcome, TrxObjectModel.TestRun testRun) { UnitTestResult testResult = new UnitTestResult(Environment.MachineName, testRun.Id, testElement, testOutcome); if (rockSteadyTestResult.ErrorMessage != null) { testResult.ErrorMessage = rockSteadyTestResult.ErrorMessage; } if (rockSteadyTestResult.ErrorStackTrace != null) { testResult.ErrorStackTrace = rockSteadyTestResult.ErrorStackTrace; } // set start and end times if (rockSteadyTestResult.EndTime != null) { testResult.EndTime = rockSteadyTestResult.EndTime.UtcDateTime; } if (rockSteadyTestResult.StartTime != null) { testResult.StartTime = rockSteadyTestResult.StartTime.UtcDateTime; } if (rockSteadyTestResult.Duration != null) { testResult.Duration = rockSteadyTestResult.Duration; } return(testResult); }
public void GetQToolsTestElementFromTestCaseShouldNotFailWhenThereIsNoTestCategoreis() { ObjectModel.TestCase testCase = CreateTestCase("TestCase1"); ObjectModel.TestResult result = new ObjectModel.TestResult(testCase); TrxLoggerObjectModel.UnitTestElement unitTestElement = Converter.GetQToolsTestElementFromTestCase(result); object[] expected = Enumerable.Empty <Object>().ToArray(); CollectionAssert.AreEqual(expected, unitTestElement.TestCategories.ToArray()); }
/// <summary> /// Override for Equals. /// </summary> /// <param name="other"> /// The object to compare. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public override bool Equals(object other) { UnitTestElement otherTest = other as UnitTestElement; if (otherTest == null) { return(false); } return(this.id.Equals(otherTest.id)); }
public void GetQToolsTestElementFromTestCaseShouldAssignTestCategoryOfUnitTestElement() { ObjectModel.TestCase testCase = CreateTestCase("TestCase1"); ObjectModel.TestResult result = new ObjectModel.TestResult(testCase); TestProperty testProperty = TestProperty.Register("MSTestDiscoverer.TestCategory", "String array property", string.Empty, string.Empty, typeof(string[]), null, TestPropertyAttributes.Hidden, typeof(TestObject)); testCase.SetPropertyValue(testProperty, new[] { "AsmLevel", "ClassLevel", "MethodLevel" }); TrxLoggerObjectModel.UnitTestElement unitTestElement = Converter.GetQToolsTestElementFromTestCase(result); object[] expected = new[] { "MethodLevel", "ClassLevel", "AsmLevel" }; CollectionAssert.AreEqual(expected, unitTestElement.TestCategories.ToArray().OrderByDescending(x => x.ToString()).ToArray()); }
/// <summary> /// Converts the rockSteady result to unit test result /// </summary> /// <param name="rockSteadyTestResult"> rock steady test result</param> /// <param name="testElement"> testElement of that test</param> /// <param name="testOutcome"> Test outcome </param> /// <param name="testRun"> test run object </param> /// <param name="trxFileDirectory"> TRX file directory</param> /// <returns> TestResult object </returns> internal static TrxObjectModel.UnitTestResult ToUnitTestResult( ObjectModel.TestResult rockSteadyTestResult, TrxObjectModel.UnitTestElement testElement, TrxObjectModel.TestOutcome testOutcome, TrxObjectModel.TestRun testRun, string trxFileDirectory) { TrxObjectModel.UnitTestResult qtoolsResult = GetQToolsTestResultFromTestResult(rockSteadyTestResult, testElement, testOutcome, testRun); // Clear exsting messages and store rocksteady result messages. qtoolsResult.TextMessages = null; UpdateResultMessages(qtoolsResult, rockSteadyTestResult); // Save result attachments to target location. UpdateTestResultAttachments(rockSteadyTestResult, qtoolsResult, testRun, trxFileDirectory, true); return(qtoolsResult); }
/// <summary> /// Initializes a new instance of the <see cref="TestResult"/> class. /// </summary> /// <param name="computerName"> /// The computer name. /// </param> /// <param name="runId"> /// The run id. /// </param> /// <param name="test"> /// The test. /// </param> /// <param name="outcome"> /// The outcome. /// </param> public UnitTestResult(string computerName, Guid runId, UnitTestElement test, TestOutcome outcome) { Debug.Assert(computerName != null, "computername is null"); Debug.Assert(test != null, "test is null"); Debug.Assert(!Guid.Empty.Equals(test.ExecutionId.Id), "ExecutionId is empty"); Debug.Assert(!Guid.Empty.Equals(test.Id.Id), "Id is empty"); this.Initialize(); this.id = new TestResultId(runId, test.ExecutionId, test.Id); this.testName = test.Name; this.testType = test.TestType; this.computerInfo = computerName; this.outcome = outcome; this.categoryId = test.CategoryId; this.relativeTestResultsDirectory = TestRunDirectories.GetRelativeTestResultsDirectory(test.ExecutionId.Id); }
/// <summary> /// Returns QToolsCommon.TestElement from rockSteady TestCase. /// </summary> /// <param name="rockSteadyTestResult"> /// The rockSteady Test Result. /// </param> /// <returns> /// The <see cref="UnitTestElement"/>. /// </returns> internal static TrxObjectModel.UnitTestElement GetQToolsTestElementFromTestCase(ObjectModel.TestResult rockSteadyTestResult) { ObjectModel.TestCase rockSteadyTestCase = rockSteadyTestResult.TestCase; // Fix for bug# 868033 // Use TMI Test id when available. This is needed to ensure that test id in trx files is same as specified in // .vsmdi files. // (This is required for test explorer: It removes all test nodes where test id is not in expected test id when merging // trx files from different batches). Guid testId = GetTmiTestId(rockSteadyTestCase); #if NET46 if (Guid.Empty.Equals(testId)) { testId = rockSteadyTestCase.Id; } #else testId = Guid.NewGuid(); #endif string testDisplayName = rockSteadyTestCase.DisplayName; // If it is an inner test case name if (!string.IsNullOrEmpty(rockSteadyTestResult.DisplayName)) { testId = Guid.NewGuid(); // Changing of guid is done so that VS can load trx otherwise it fails with duplicate id error. testDisplayName = rockSteadyTestResult.DisplayName; } TrxObjectModel.TestMethod testMethod = GetTestMethod(testDisplayName, rockSteadyTestCase); // convert the rocksteady tests to TestElement. TrxObjectModel.UnitTestElement testElement = new TrxObjectModel.UnitTestElement(testId, testDisplayName, rockSteadyTestCase.ExecutorUri.ToString(), testMethod); testElement.ExecutionId = new TrxObjectModel.TestExecId(Guid.NewGuid()); testElement.AssignCodeBase(rockSteadyTestCase.Source); testElement.Storage = rockSteadyTestCase.Source; if (rockSteadyTestCase.Traits != null) { ObjectModel.Trait priorityTrait = rockSteadyTestCase.Traits.FirstOrDefault(t => t.Name.Equals("Priority")); if (priorityTrait != null) { int priorityValue; if (Int32.TryParse(priorityTrait.Value, out priorityValue)) { testElement.Priority = priorityValue; } } ObjectModel.Trait ownerTrait = rockSteadyTestCase.Traits.FirstOrDefault(t => t.Name.Equals("Owner")); if (ownerTrait != null) { testElement.Owner = ownerTrait.Value; } } // reading TestCategories from the testcase var testCategories = GetCustomPropertyValueFromTestCase(rockSteadyTestCase, "MSTestDiscoverer.TestCategory"); foreach (string testCategory in testCategories) { testElement.TestCategories.Add(testCategory); } return(testElement); }