示例#1
0
        /// <summary>
        /// Called when a test result is received.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The eventArgs.
        /// </param>
        public void TestResultHandler(object sender, ObjectModel.Logging.TestResultEventArgs e)
        {
            // Create test run
            if (this.testRun == null)
            {
                CreateTestRun();
            }

            // 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);
            }

            var testType    = Converter.GetTestType(e.Result);
            var executionId = Converter.GetExecutionId(e.Result);

            // Setting parent properties like parent result, parent test element, parent execution id.
            var parentExecutionId = Converter.GetParentExecutionId(e.Result);
            var parentTestResult  = GetTestResult(parentExecutionId);
            var parentTestElement = (parentTestResult != null) ? GetTestElement(parentTestResult.Id.TestId) : null;

            // Switch to flat test results in case any parent related information is missing.
            if (parentTestResult == null || parentTestElement == null || parentExecutionId == Guid.Empty)
            {
                parentTestResult  = null;
                parentTestElement = null;
                parentExecutionId = Guid.Empty;
            }

            // Create trx test element from rocksteady test case
            var testElement = GetOrCreateTestElement(executionId, parentExecutionId, testType, parentTestElement, e.Result);

            // Update test links. Test Links are updated in case of Ordered test.
            UpdateTestLinks(testElement, parentTestElement);

            // Convert the rocksteady result to trx test result
            var testResult = CreateTestResult(executionId, parentExecutionId, testType, testElement, parentTestElement, parentTestResult, e.Result);

            // Update test entries
            UpdateTestEntries(executionId, parentExecutionId, testElement, parentTestElement);

            // 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++;
            }
        }
示例#2
0
        /// <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);
        }