A result from a test scenario.
        /// <summary>
        /// Track the results for our execution and also track the fail state.
        /// </summary>
        /// <param name="result">Scenario result to process.</param>
        public void TrackScenarioResult(ScenarioResult result)
        {
            Results.Add(result);
            State.IncrementTotalScenarios();

            if (result.Result != TestOutcome.Passed)
            {
                State.IncrementFailures();
            }
        }
 /// <summary>
 /// Process a UTF result message.
 /// </summary>
 /// <param name="logMessage">The log message object.</param>
 private void ProcessResult(LogMessage logMessage)
 {
     if (logMessage.HasDecorator(UnitTestLogDecorator.TestMethodMetadata))
     {
         ScenarioResult sr = (ScenarioResult)logMessage[UnitTestLogDecorator.ScenarioResult];
         if (sr.Result != TestOutcome.Passed)
         {
             _failures.Add(sr);
         }
     }
 }
        /// <summary>
        /// Process an unhandled exception for the method.
        /// </summary>
        /// <param name="sender">Source object.</param>
        /// <param name="e">Unhandled exception event arguments.</param>
        private void UnhandledMethodException(object sender, UnhandledExceptionEventArgs e)
        {
            TestOutcome res;
            Exception   excp = (Exception)e.ExceptionObject;

            IExpectedException expected = _testMethod.ExpectedException;
            Type expectedType           = expected != null ? expected.ExceptionType : null;

            if (excp == null)
            {
                throw new InvalidOperationException();
            }

            // Unwrap the Exception
            if (excp.GetType() == typeof(TargetInvocationException) && excp.InnerException != null)
            {
                excp = excp.InnerException;
            }

            res = excp is TimeoutException ? TestOutcome.Timeout : excp.Message.Contains("Inconclusive") ? TestOutcome.Inconclusive : TestOutcome.Failed;
            if (expected != null)
            {
                // Was it expected?
                Type excpType = excp.GetType();
                if (excpType == expectedType || excpType.IsSubclassOf(expectedType))
                {
                    res = TestOutcome.Passed;
                }
                else
                {
                    LogWriter.IncorrectException(_testMethod.ExpectedException.ExceptionType, excpType, _testClass, _testMethod);
                    LogWriter.LogException(excp, _testClass, _testMethod);
                }
            }
            else
            {
                // Regular Exception type
                LogWriter.LogException(excp, _testClass, _testMethod);
            }

            // Create the result
            _result = new ScenarioResult(_testMethod, _testClass, res, excp);
            SetResultTimes();

            // If an asynchronous method, do not run any additional parts of the method container
            if (_mainTestMethodContainer.RemainingWork)
            {
                while (_mainTestMethodContainer.RemainingWork)
                {
                    _mainTestMethodContainer.Dequeue();
                }
            }
        }
        /// <summary>
        /// Log the result of a unit test scenario.
        /// </summary>
        /// <param name="result">The result of the test.</param>
        public void TestResult(ScenarioResult result)
        {
            TestOutcome outcome = result.Result;
            string      name    = result.TestClass.Name + "." + result.TestMethod.Name;
            LogMessage  m       = Create(LogMessageType.TestResult, name);

            MarkUnitTestMessage(m);
            DecorateNameProperty(m, result.TestMethod.Name);
            DecorateTestGranularity(m, TestGranularity.TestScenario);
            m[UnitTestLogDecorator.ScenarioResult]     = result;
            m[UnitTestLogDecorator.TestMethodMetadata] = result.TestMethod;
            m[UnitTestLogDecorator.TestClassMetadata]  = result.TestClass;
            DecorateTestOutcome(m, outcome);
            Enqueue(m);
        }
        /// <summary>
        /// Process a UTF result message.
        /// </summary>
        /// <param name="logMessage">The log message object.</param>
        private void ProcessResult(LogMessage logMessage)
        {
            if (logMessage.HasDecorator(UnitTestLogDecorator.TestMethodMetadata))
            {
                TestOutcome    result = (TestOutcome)logMessage[LogDecorator.TestOutcome];
                ITestMethod    method = (ITestMethod)logMessage[UnitTestLogDecorator.TestMethodMetadata];
                ITestClass     test   = (ITestClass)logMessage[UnitTestLogDecorator.TestClassMetadata];
                ScenarioResult sr     = (ScenarioResult)logMessage[UnitTestLogDecorator.ScenarioResult];

                string   storage         = CurrentAssemblyName;
                string   codeBase        = CurrentAssemblyName;
                string   adapterTypeName = TestAdapterTypeName;
                string   className       = test.Name;
                string   testListName    = TestListName;
                string   computerName    = ComputerName;
                DateTime startTime       = sr.Started;
                DateTime endTime         = sr.Finished;
                _writer.AddTestMethodResult(method, storage, codeBase, adapterTypeName, className, testListName, computerName, startTime, endTime, result);
                _writer.IncrementResults(result);
            }
        }
        protected override void Before_all_tests()
        {
            base.Before_all_tests();

            var mockTestMethod = new MockTestMethod();
            var mockTestClass = new MockTestClass();

            var scenarioResult = new ScenarioResult(
                mockTestMethod,
                mockTestClass,
                TestOutcome.Passed,
                null);

            _logMessage = new LogMessage(LogMessageType.TestResult);
            _logMessage.Decorators.Add(UnitTestLogDecorator.IsUnitTestMessage, true);
            _logMessage.Decorators.Add(LogDecorator.NameProperty, "some_test_method_name_here");
            _logMessage.Decorators.Add(LogDecorator.TestGranularity, TestGranularity.TestScenario);
            _logMessage.Decorators.Add(UnitTestLogDecorator.ScenarioResult, scenarioResult);
            _logMessage.Decorators.Add(UnitTestLogDecorator.TestMethodMetadata, mockTestMethod);
            _logMessage.Decorators.Add(UnitTestLogDecorator.TestClassMetadata, mockTestClass);
            _logMessage.Decorators.Add(LogDecorator.TestOutcome, TestOutcome.Passed);
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the TestMethodCompletedEventArgs
 /// type.
 /// </summary>
 /// <param name="result">The result instance.</param>
 /// <param name="harness">The unit test harness.</param>
 public TestMethodCompletedEventArgs(ScenarioResult result, UnitTestHarness harness)
     : base(harness)
 {
     Result = result;
 }
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the TestMethodCompletedEventArgs
 /// type.
 /// </summary>
 /// <param name="result">The result instance.</param>
 public TestMethodCompletedEventArgs(ScenarioResult result)
     : this(result, result.TestClass.Assembly.TestHarness)
 {
 }
 /// <summary>
 /// Creates the ScenarioResult instance for this test method.
 /// </summary>
 /// <param name="outcome">The initial test outcome value.</param>
 private void CreateNewResult(TestOutcome outcome)
 {
     _result = new ScenarioResult(_testMethod, _testClass, outcome, null);
     SetResultTimes();
 }
        /// <summary>
        /// Track the results for our execution and also track the fail state.
        /// </summary>
        /// <param name="result">Scenario result to process.</param>
        public void TrackScenarioResult(ScenarioResult result)
        {
            Results.Add(result);
            State.IncrementTotalScenarios();

            if (result.Result != TestOutcome.Passed)
            {
                State.IncrementFailures();
            }
        }
        /// <summary>
        /// Process a result.
        /// </summary>
        /// <param name="result">The result data.</param>
        private void ProcessResult(ScenarioResult result)
        {
            TestClassData tac = GetClassModel(result.TestClass);
            TestMethodData tmd = GetMethodModel(result.TestMethod, tac);

            tmd.IsRunning = false;

            tmd.IsNotable = !tmd.Passed;

            if (_d == null)
            {
                return;
            }

            // Link to previous
            tmd.PreviousResult = _lastResult;
            _lastResult = tmd;

            _d.RunScenarios++;
            if (result.Result != TestOutcome.Passed)
            {
                _d.FailedScenarios++;

                // Link to previous failure
                tmd.PreviousFailingResult = _lastFailingResult;
                _lastFailingResult = tmd;

                // Automatically check the item for the user
                tmd.IsChecked = true;
            }

            tmd.Result = result;
        }
Beispiel #12
0
        /// <summary>
        /// Process an unhandled exception for the method.
        /// </summary>
        /// <param name="sender">Source object.</param>
        /// <param name="e">Unhandled exception event arguments.</param>
        private void UnhandledMethodException(object sender, UnhandledExceptionEventArgs e)
        {
            TestOutcome res;
            Exception excp = (Exception)e.ExceptionObject;

            IExpectedException expected = _testMethod.ExpectedException;
            Type expectedType = expected != null ? expected.ExceptionType : null;

            if (excp == null)
            {
                throw new InvalidOperationException();
            }

            // Unwrap the Exception
            if (excp.GetType() == typeof(TargetInvocationException) && excp.InnerException != null)
            {
                excp = excp.InnerException;
            }

            res = excp is TimeoutException ? TestOutcome.Timeout : excp.Message.Contains("Inconclusive") ? TestOutcome.Inconclusive : TestOutcome.Failed;
            if (expected != null)
            {
                // Was it expected?
                Type excpType = excp.GetType();
                if (excpType == expectedType || excpType.IsSubclassOf(expectedType))
                {
                    res = TestOutcome.Passed;
                }
                else
                {
                    LogWriter.IncorrectException(_testMethod.ExpectedException.ExceptionType, excpType, _testClass, _testMethod);
                    LogWriter.LogException(excp, _testClass, _testMethod);
                }
            }
            else
            {
                // Regular Exception type
                LogWriter.LogException(excp, _testClass, _testMethod);
            }

            // Create the result
            _result = new ScenarioResult(_testMethod, _testClass, res, excp);
            SetResultTimes();

            // If an asynchronous method, do not run any additional parts of the method container
            if (_mainTestMethodContainer.RemainingWork)
            {
                while (_mainTestMethodContainer.RemainingWork)
                {
                    _mainTestMethodContainer.Dequeue();
                }
            }
        }
Beispiel #13
0
 /// <summary>
 /// Creates the ScenarioResult instance for this test method.
 /// </summary>
 /// <param name="outcome">The initial test outcome value.</param>
 private void CreateNewResult(TestOutcome outcome)
 {
     _result = new ScenarioResult(_testMethod, _testClass, outcome, null);
     SetResultTimes();
 }
 /// <summary>
 /// Initializes a new instance of the TestMethodCompletedEventArgs
 /// type.
 /// </summary>
 /// <param name="result">The result instance.</param>
 /// <param name="harness">The unit test harness.</param>
 public TestMethodCompletedEventArgs(ScenarioResult result, UnitTestHarness harness)
     : base(harness)
 {
     Result = result;
 }
 /// <summary>
 /// Initializes a new instance of the TestMethodCompletedEventArgs
 /// type.
 /// </summary>
 /// <param name="result">The result instance.</param>
 public TestMethodCompletedEventArgs(ScenarioResult result)
     : this(result, result.TestClass.Assembly.TestHarness)
 {
 }
 /// <summary>
 /// Log the result of a unit test scenario.
 /// </summary>
 /// <param name="result">The result of the test.</param>
 public void TestResult(ScenarioResult result)
 {
     TestOutcome outcome = result.Result;
     string name = result.TestClass.Name + "." + result.TestMethod.Name;
     LogMessage m = Create(LogMessageType.TestResult, name);
     MarkUnitTestMessage(m);
     DecorateNameProperty(m, result.TestMethod.Name);
     DecorateTestGranularity(m, TestGranularity.TestScenario);
     m[UnitTestLogDecorator.ScenarioResult] = result;
     m[UnitTestLogDecorator.TestMethodMetadata] = result.TestMethod;
     m[UnitTestLogDecorator.TestClassMetadata] = result.TestClass;
     DecorateTestOutcome(m, outcome);
     Enqueue(m);
 }