/// <summary> /// Creates test run. /// </summary> private void CreateTestRun() { // Skip run creation if already exists. if (testRun != null) { return; } Guid runId = Guid.NewGuid(); this.testRun = new TestRun(runId); // We cannot rely on the StartTime for the first test result // In case of parallel, first test result is the fastest test and not the one which started first. // Setting Started to DateTime.Now in Intialize will make sure we include the startup cost, which was being ignored earlier. // This is in parity with the way we set this.testRun.Finished this.testRun.Started = this.testRunStartTime; // Save default test settings string runDeploymentRoot = FileHelper.ReplaceInvalidFileNameChars(this.testRun.Name); TestRunConfiguration testrunConfig = new TestRunConfiguration("default"); testrunConfig.RunDeploymentRootDirectory = runDeploymentRoot; this.testRun.RunConfiguration = testrunConfig; }
/// <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); }
// Initializes trx logger cache. private void InitializeInternal() { this.results = new List <TrxLoggerObjectModel.UnitTestResult>(); this.testElements = new List <UnitTestElement>(); this.entries = new List <TestEntry>(); this.runLevelErrorsAndWarnings = new List <RunInfo>(); this.testRun = null; this.totalTests = 0; this.passTests = 0; this.failTests = 0; this.runLevelStdOut = new StringBuilder(); this.testRunStartTime = DateTime.Now; }
// Initializes trx logger cache. private void InitializeInternal() { this.results = new ConcurrentDictionary <Guid, ITestResult>(); this.innerResults = new ConcurrentDictionary <Guid, ITestResult>(); this.testElements = new ConcurrentDictionary <Guid, ITestElement>(); this.entries = new ConcurrentDictionary <Guid, TestEntry>(); this.innerTestEntries = new ConcurrentDictionary <Guid, TestEntry>(); this.runLevelErrorsAndWarnings = new List <RunInfo>(); this.testRun = null; this.totalTests = 0; this.passTests = 0; this.failTests = 0; this.runLevelStdOut = new StringBuilder(); this.testRunStartTime = DateTime.UtcNow; }
/// <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> /// Sets the test run the test was executed in /// </summary> /// <param name="testRun">The test run the test was executed in</param> internal virtual void SetTestRun(TestRun testRun) { Debug.Assert(testRun != null, "'testRun' is null"); this.testRun = testRun; }
/// <summary> /// Called when a test result is received. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The eventArgs. /// </param> internal void TestResultHandler(object sender, ObjectModel.Logging.TestResultEventArgs e) { if (this.testRun == null) { Guid runId = Guid.NewGuid(); this.testRun = new TestRun(runId); // We cannot rely on the StartTime for the first test result // In case of parallel, first test result is the fastest test and not the one which started first. // Setting Started to DateTime.Now in Intialize will make sure we include the startup cost, which was being ignored earlier. // This is in parity with the way we set this.testRun.Finished this.testRun.Started = this.testRunStartTime; // Save default test settings string runDeploymentRoot = FileHelper.ReplaceInvalidFileNameChars(this.testRun.Name); TestRunConfiguration testrunConfig = new TestRunConfiguration("default"); testrunConfig.RunDeploymentRootDirectory = runDeploymentRoot; this.testRun.RunConfiguration = testrunConfig; } // Convert skipped test to a log entry as that is the behaviour of mstest. if (e.Result.Outcome == ObjectModel.TestOutcome.Skipped) { this.HandleSkippedTest(e.Result); } // Create MSTest test element from rocksteady test case UnitTestElement testElement = Converter.ToUnitTestElement(e.Result); // Conver the rocksteady result to MSTest result TrxLoggerObjectModel.TestOutcome testOutcome = Converter.ToOutcome(e.Result.Outcome); TrxLoggerObjectModel.UnitTestResult testResult = Converter.ToUnitTestResult(e.Result, testElement, testOutcome, this.testRun, this.testResultsDirPath); // Set various counts (passtests, failed tests, total tests) this.totalTests++; if (testResult.Outcome == TrxLoggerObjectModel.TestOutcome.Failed) { this.testRunOutcome = TrxLoggerObjectModel.TestOutcome.Failed; this.failTests++; } else if (testResult.Outcome == TrxLoggerObjectModel.TestOutcome.Passed) { this.passTests++; } // Add results to in-memory lists that are saved to the xml at completion. this.results.Add(testResult); if (!this.testElements.Contains(testElement)) { this.testElements.Add(testElement); } // create a test entry TestEntry te = new TestEntry(testElement.Id, TestListCategory.UncategorizedResults.Id); te.ExecId = testElement.ExecutionId; this.entries.Add(te); }