Example #1
0
 public void OnTestFailed(object sender, TestResultEventArgs args) {
 }
Example #2
0
      private void CreateResultNode(TestResultEventArgs args) {
         var test = _document.CreateElement("test");
         var name = _document.CreateAttribute("name");
         name.Value = args.ClassName + "." + args.MethodName;
         test.Attributes.Append(name);
         _assembly.AppendChild(test);

         test.Attributes.Append(CreateAttributeOnTest("test-result", args.TestResult.ToString()));
         test.Attributes.Append(CreateAttributeOnTest("reason", args.Reason));
         test.Attributes.Append(CreateAttributeOnTest("duration", (((double) args.Duration) / 1000000).ToString("0.000")));
         test.Attributes.Append(CreateAttributeOnTest("asserts", args.AssertCount.ToString()));
      }
Example #3
0
 public void OnTestSkipped(object sender, TestResultEventArgs args) {
    throw new Exception("The method or operation is not implemented.");
 }
Example #4
0
 private void StopTimer(TestResultEventArgs trea) {
    _timer.Stop();
    trea.Duration = ((ulong)_timer.ElapsedTicks) * _nanosecsPerTick;
    trea.AssertCount = _framework.AssertionCount;
    if( _bExpectedExceptionThrown ) {
       trea.AssertCount++;
    }
 }
Example #5
0
 private void OnTestError(object sender, TestResultEventArgs args) {
    _errorCount++;
    _assemblyErrorCount++;
    CreateResultNode(args);
 }
 public void OnTestFailed(object sender, TestResultEventArgs args) {
    _messages += " TF:" + args.MethodName + " " + args.Reason;
    _failureItems.Add(string.Format("{0}#{1}#{2}#",
       args.AssemblyName,
       args.ClassName,
       args.MethodName));
 }
Example #7
0
 private TestResultEventArgs Prepare(ITestListener listener) {
    StartTimer();
    var trea = new TestResultEventArgs(
       _methodInfo.DeclaringType.Assembly.FullName,
       _fixture.FullName, _methodInfo.Name, string.Empty, 0);
    _framework.ResetAssertionCounter();
    listener.OnTestStarted(new TestMethodInfo(this), trea);
    _bFailure = false;
    _bError = false;
    return trea;
 }
 private void ReportError(ITestListener listener, string errorReason) {
    var trea = new TestResultEventArgs(AssemblyName,
       Fixture.FullName, Name, errorReason, 0);
    listener.OnTestError(new TestMethodInfo(this), trea);
 }
Example #9
0
 private void FireAndForget(Delegate handler, TestResultEventArgs args) {
    foreach (TestEventHandler teh in handler.GetInvocationList()) {
       teh.BeginInvoke(_loader, args, TestEventHandlerAsyncCallback, teh);
    }
 }
 public override void OnTestFailed(object sender, TestResultEventArgs args) {
    FailureCount++;
    _reason = args.Reason;
 }
 public override void OnTestPassed(object sender, TestResultEventArgs args) {
    _nameOfExecutedTest = args.MethodName;
 }
 public override void OnTestError(object sender, TestResultEventArgs args) {
    ErrorCount++;
    _reason = args.Reason;
 }
Example #13
0
      /// <summary>
      /// Takes an exception and extracts relevant stack information for
      /// reporting a test result.
      /// </summary>
      /// <param name="e">An exception that was thrown.</param>
      /// <param name="trea">The TestResultEventArgs.</param>
      internal static void ExtractLocation(Exception e, TestResultEventArgs trea) {
         if ((e as TargetInvocationException) != null
            && e.InnerException != null) {
            ExtractLocation(e.InnerException, trea);
         }
         else {
            trea.StackInfo = new List<StackFrameInfo>();
            if (e.StackTrace != null) {
// ReSharper disable PossibleNullReferenceException
               foreach (var sf in (new StackTrace(e, true)).GetFrames()) {
// ReSharper restore PossibleNullReferenceException
                  // Search for first non-csUnit location [26mar07, ml]
                  var fullName = sf.GetMethod().DeclaringType.FullName;
                  if (fullName.StartsWith("csUnit")
                     && !fullName.Contains(".Tests.")) {
                     continue;
                  }
                  trea.StackInfo.Add(new StackFrameInfo(sf));
               }
            }
         }
      }
Example #14
0
 public void OnTestSkipped(object sender, TestResultEventArgs args) {
 }
Example #15
0
 public void OnTestStarted(object sender, TestResultEventArgs args) {
    _messages += " TS:" + args.MethodName;
 }
Example #16
0
 public void OnTestFailed(object sender, TestResultEventArgs args) {
    lock (this) {
       if (_loader.TestFailed != null) {
          FireAndForget(_loader.TestFailed, args);
       }
       CheckAbortThread();
    }
 }
Example #17
0
 public void OnTestPassed(object sender, TestResultEventArgs args) {
    _messages += " TP:" + args.MethodName;
    _passedItems.Add(string.Format("{0}#{1}#{2}#",
       args.AssemblyName,
       args.ClassName,
       args.MethodName));
 }
Example #18
0
      /// <summary>
      /// Reports an exception.
      /// </summary>
      /// <param name="ex">The exception</param>
      /// <param name="fixtureName">Name of the fixture.</param>
      /// <param name="testMethodName">Name of the test method.</param>
      private void ReportException(Exception ex, String fixtureName, String testMethodName) {
         var realException = ex;

         if( realException is TargetInvocationException ) {
            realException = realException.InnerException;
         }

         var trea = new TestResultEventArgs(AssemblyName, fixtureName, testMethodName,
                                            realException.ToString(), 0) {
                          AssertCount = _framework.AssertionCount
                       };
         Util.ExtractLocation(realException, trea);
         if( realException.GetType() == typeof(TestFailed) ) {
            _testListener.OnTestFailed(new TestFixtureInfo(this), trea);
         }
         else if( realException is ThreadAbortException ) {
            throw realException;
         }
         else {
            _testListener.OnTestError(new TestFixtureInfo(this), trea);
         }
      }
Example #19
0
 public void OnTestSkipped(object sender, TestResultEventArgs args) {
    _ignoredItems.Add(string.Format("{0}#{1}#{2}#{3}#",
       args.AssemblyName,
       args.ClassName,
       args.MethodName,
       args.Reason));
 }
Example #20
0
      /// <summary>
      /// Creates an instance of a fixture.
      /// </summary>
      /// <returns></returns>
      private bool CreateObject() {
         var ci = _fixtureType.GetConstructor(
            BindingFlags.Instance | BindingFlags.Public, null,
            CallingConventions.HasThis, new Type[0], null);

         if(ci != null) {
            return InvokeMethod(ci);
         }
         
         var trea = new TestResultEventArgs(AssemblyName,
                                            Name, string.Empty, "No public default constructor found.", 0)
                       {
                          AssertCount = _framework.AssertionCount
                       };
         _testListener.OnTestError(new TestFixtureInfo(this), trea);
         return false;
      }
Example #21
0
 private void HandleException(Exception e, TestResultEventArgs trea) {
    if(e.InnerException != null
       && e.GetType().Equals(typeof(TargetInvocationException))) {
       HandleException(e.InnerException, trea);
       return;
    }
    if(_framework.IsFailure(e)) { // Filter out failed assertions. [13jan07, ml]
       HasFailed(e.Message);
       trea.TestResult = TestResultCategory.Failure;
    }
    else {
       HasError("Unexpected " + e.GetType().FullName + ": " + e.Message);
       trea.TestResult = TestResultCategory.Error;
    }
 }
            void ITestListener.OnTestStarted(object sender, TestResultEventArgs args)
            {
                ITestCommand fixtureCommand;
                if (!testCommandsByName.TryGetValue(args.ClassName, out fixtureCommand))
                    return;

                ITestCommand testCommand;
                string testName = args.ClassName + @"." + args.MethodName;
                if (!testCommandsByName.TryGetValue(testName, out testCommand))
                    return;

                ITestContext fixtureContext = GetFixtureContext(fixtureCommand);
                ITestContext testContext = testCommand.StartPrimaryChildStep(fixtureContext.TestStep);
                testContext.LifecyclePhase = LifecyclePhases.Execute;
                progressMonitor.SetStatus(testCommand.Test.Name);
                testContextStack.Push(testContext);
            }
Example #23
0
 private void OnTestFailed(object sender, TestResultEventArgs args) {
    _failureCount++;
    _assemblyFailureCount++;
    CreateResultNode(args);
 }
            void ITestListener.OnTestFailed(object sender, TestResultEventArgs args)
            {
                TestFinished(TestOutcome.Failed, args.ClassName, args.MethodName, args.AssertCount, args.Duration, args.Reason,
                    delegate(ITestContext context)
                    {
                        if (args.Failure != null)
                        {
                            MarkupStreamWriter log = context.LogWriter.Failures;

                            using (log.BeginSection(Resources.CSUnitTestController_ResultMessageSectionName))
                            {
                                if (!String.IsNullOrEmpty(args.Failure.Expected))
                                    log.WriteLine(args.Failure.Expected);
                                if (!String.IsNullOrEmpty(args.Failure.Actual))
                                    log.WriteLine(args.Failure.Actual);
                                if (!String.IsNullOrEmpty(args.Failure.Message))
                                    log.WriteLine(args.Failure.Message);
                            }

                            using (log.BeginSection(Resources.CSUnitTestController_ResultStackTraceSectionName))
                            {
                                using (log.BeginMarker(Marker.StackTrace))
                                {
                                    log.Write(args.Failure.StackTrace);
                                }
                            }
                        }
                    });
                Interlocked.Increment(ref fixtureFailureCount);
            }
Example #25
0
 private void OnTestSkipped(object sender, TestResultEventArgs args) {
    _skippedCount++;
    _assemblySkippedCount++;
    CreateResultNode(args);
 }
            void ITestListener.OnTestError(object sender, TestResultEventArgs args)
            {
                TestFinished(TestOutcome.Error, args.ClassName, args.MethodName, args.AssertCount, args.Duration, args.Reason,
                    delegate(ITestContext context)
                    {
                        if (!String.IsNullOrEmpty(args.Reason))
                        {
                            MarkupStreamWriter log = context.LogWriter.Failures;

                            using (log.BeginSection(Resources.CSUnitTestController_ResultMessageSectionName))
                            {
                                log.Write(args.Reason);
                            }
                        }
                    });
                Interlocked.Increment(ref fixtureErrorCount);
            }
 void OnTestEvent(object sender, TestResultEventArgs args) {
    UpdateStatistics(args.ClassName, args.MethodName, args.Duration, args.AssertCount);
 }
 void ITestListener.OnTestSkipped(object sender, TestResultEventArgs args)
 {
     TestFinished(TestOutcome.Skipped, args.ClassName, args.MethodName, args.AssertCount, args.Duration, args.Reason, null);
 }
 private void OnTestErrorOrFail(object sender, TestResultEventArgs args) {
    _failedTestCriterion.Add(args.AssemblyName, args.ClassName, args.MethodName);
    Enabled = true;
 }
Example #30
0
 public void OnTestError(object sender, TestResultEventArgs args) {
 }