Beispiel #1
0
        protected virtual void DoOneTimeBeforeTestSuiteActions(TestResult suiteResult)
        {
            try
            {
                ExecuteActions(ActionPhase.Before);
                TestExecutionContext.CurrentContext.Update();
            }
            catch (Exception ex)
            {
                if (ex is NUnitException || ex is System.Reflection.TargetInvocationException)
                {
                    ex = ex.InnerException;
                }

                if (ex is InvalidTestFixtureException)
                {
                    suiteResult.Invalid(ex.Message);
                }
                else if (IsIgnoreException(ex))
                {
                    this.RunState = RunState.Ignored;
                    suiteResult.Ignore(ex.Message);
                    suiteResult.StackTrace = ex.StackTrace;
                    this.IgnoreReason      = ex.Message;
                }
                else if (IsAssertException(ex))
                {
                    suiteResult.Failure(ex.Message, ex.StackTrace, FailureSite.SetUp);
                }
                else
                {
                    suiteResult.Error(ex, FailureSite.SetUp);
                }
            }
        }
Beispiel #2
0
        public override TestResult Run(EventListener listener, ITestFilter filter)
        {
            using (new global::NUnit.Core.TestContext())
            {
                var testResult = new TestResult(this);
                Log.Debug("Test Starting: " + TestName.FullName);
                listener.TestStarted(TestName);
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                switch (RunState)
                {
                    case RunState.Runnable:
                    case RunState.Explicit:
                        DoTest(_test, testResult);
                        break;
                    case RunState.NotRunnable:
                        testResult.Invalid(IgnoreReason);
                        break;
                    case RunState.Ignored:
                        testResult.Ignore(IgnoreReason);
                        break;
                    default:
                        testResult.Skip(IgnoreReason);
                        break;

                }

                stopwatch.Stop();
                testResult.Time = stopwatch.Elapsed.Seconds;

                listener.TestFinished(testResult);
                return testResult;
            }
        }
Beispiel #3
0
        private TestResult SkipTest()
        {
            TestResult testResult = new TestResult(this);

            switch (this.RunState)
            {
            case RunState.Skipped:
            default:
                testResult.Skip(IgnoreReason);
                break;

            case RunState.NotRunnable:
                if (BuilderException != null)
                {
                    testResult.Invalid(BuilderException);
                }
                else
                {
                    testResult.Invalid(IgnoreReason);
                }
                break;

            case RunState.Ignored:
                testResult.Ignore(IgnoreReason);
                break;
            }

            return(testResult);
        }
Beispiel #4
0
        public override TestResult Run(EventListener listener, ITestFilter filter)
        {
            var result = new TestResult(this);

            lock (testClosure) {
                try {
                    testClosure.TestMethod();
                    TestNonExceptionCondition(result);
                } catch (IgnoreException iex) {
                    result.Ignore(iex.Message);
                } catch (InconclusiveException icex) {
                    result.Invalid(icex.Message);
                } catch (Exception ex) {
                    TestExceptionCondition(result, ex);
                }

                try {
                    testClosure.TearDown();
                } catch (Exception ex) {
                    result.Failure("Exception in tear-down: "+ex.Message, ex.StackTrace);
                }
            }

            listener.TestFinished(result);
            return result;
        }
Beispiel #5
0
        protected virtual void DoOneTimeSetUp(TestResult suiteResult)
        {
            if (FixtureType != null)
            {
                try
                {
                    // In case TestFixture was created with fixture object
                    if (Fixture == null && !IsStaticClass(FixtureType))
                    {
                        CreateUserFixture();
                    }

                    if (this.Properties["_SETCULTURE"] != null)
                    {
                        TestContext.CurrentCulture =
                            new System.Globalization.CultureInfo((string)Properties["_SETCULTURE"]);
                    }

                    if (this.fixtureSetUpMethods != null)
                    {
                        foreach (MethodInfo fixtureSetUp in fixtureSetUpMethods)
                        {
                            Reflect.InvokeMethod(fixtureSetUp, fixtureSetUp.IsStatic ? null : Fixture);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex is NUnitException || ex is System.Reflection.TargetInvocationException)
                    {
                        ex = ex.InnerException;
                    }

                    if (IsIgnoreException(ex))
                    {
                        this.RunState = RunState.Ignored;
                        suiteResult.Ignore(ex.Message);
                        suiteResult.StackTrace = ex.StackTrace;
                        this.IgnoreReason      = ex.Message;
                    }
                    else
                    {
                        if (IsAssertException(ex))
                        {
                            suiteResult.Failure(ex.Message, ex.StackTrace, FailureSite.SetUp);
                        }
                        else
                        {
                            suiteResult.Error(ex, FailureSite.SetUp);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public override TestResult Run(EventListener listener, ITestFilter filter)
        {
            using (new TestContext())
            {
                TestResult testResult = new TestResult(this);

                ContextDictionary context = Context;
                context._testResult   = testResult;
                context["TestName"]   = this.TestName.Name;
                context["Properties"] = this.Properties;

                CallContext.SetData("NUnit.Framework.TestContext", context);

                log.Debug("Test Starting: " + this.TestName.FullName);
                listener.TestStarted(this.TestName);
                long startTime = DateTime.Now.Ticks;

                switch (this.RunState)
                {
                case RunState.Runnable:
                case RunState.Explicit:
                    Run(testResult);
                    break;

                case RunState.Skipped:
                default:
                    testResult.Skip(IgnoreReason);
                    break;

                case RunState.NotRunnable:
                    if (BuilderException != null)
                    {
                        testResult.Invalid(BuilderException);
                    }
                    else
                    {
                        testResult.Invalid(IgnoreReason);
                    }
                    break;

                case RunState.Ignored:
                    testResult.Ignore(IgnoreReason);
                    break;
                }

                long   stopTime = DateTime.Now.Ticks;
                double time     = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond;
                testResult.Time = time;

                listener.TestFinished(testResult);
                return(testResult);
            }
        }
        TestResult CreateTestResultFromExpectation(IExpectation expectation)
        {
            var result = new TestResult(new TestName { Name = expectation.Message });

            if (expectation.IsFail)
                result.Failure(expectation.ToString(), "");
            else if (expectation.IsPass)
                result.Success();
            else if (expectation.IsPending)
                result.Ignore(expectation.ToString(), "");

            return result;
        }
        public void ProcessException(Exception exception, TestResult testResult)
        {
            if (exception is NUnitException)
            {
                exception = exception.InnerException;
            }

            if (IsExpectedExceptionType(exception))
            {
                if (IsExpectedMessageMatch(exception))
                {
                    if (exceptionHandler != null)
                    {
                        Reflect.InvokeMethod(exceptionHandler, testMethod.Fixture, exception);
                    }

                    testResult.Success();
                }
                else
                {
                    testResult.Failure(WrongTextMessage(exception), GetStackTrace(exception));
                }
            }
            else
            {
                switch (NUnitFramework.GetResultState(exception))
                {
                case ResultState.Failure:
                    testResult.Failure(exception.Message, exception.StackTrace);
                    break;

                case ResultState.Ignored:
                    testResult.Ignore(exception);
                    break;

                case ResultState.Inconclusive:
                    testResult.SetResult(ResultState.Inconclusive, exception, FailureSite.Test);
                    break;

                case ResultState.Success:
                    testResult.Success(exception.Message);
                    break;

                default:
                    testResult.Failure(WrongTypeMessage(exception), GetStackTrace(exception));
                    break;
                }
            }
        }
Beispiel #9
0
 protected void RecordException(Exception ex, TestResult testResult)
 {
     if (IsIgnoreException(ex))
     {
         testResult.Ignore(ex.Message);
     }
     else if (IsAssertException(ex))
     {
         testResult.Failure(ex.Message, ex.StackTrace);
     }
     else
     {
         testResult.Error(ex);
     }
 }
Beispiel #10
0
        public override void RunTestMethod(TestResult testResult)
        {
            using (var runner = new Runner(Spec))
            {
                var example = runner.Run(() => RunBaseTestMethod(testResult), new TestResultExampleReporter(testResult));

                if (example.IsFail)
                    testResult.Failure(GetTestResultMessageForResultState(testResult, ResultState.Failure, "Failing"), "");

                if (example.IsPass)
                    testResult.Success();

                if (example.IsPending)
                    testResult.Ignore(GetTestResultMessageForResultState(testResult, ResultState.Ignored, "Pending"));
            }
        }
Beispiel #11
0
        protected virtual void DoOneTimeSetUp(TestResult suiteResult)
        {
            if (FixtureType != null)
            {
                try
                {
                    if (Fixture == null) // In case TestFixture was created with fixture object
                    {
                        CreateUserFixture();
                    }

                    if (this.fixtureSetUp != null)
                    {
                        Reflect.InvokeMethod(fixtureSetUp, Fixture);
                    }
                }
                catch (Exception ex)
                {
                    if (ex is NUnitException || ex is System.Reflection.TargetInvocationException)
                    {
                        ex = ex.InnerException;
                    }

                    if (IsIgnoreException(ex))
                    {
                        this.RunState = RunState.Ignored;
                        suiteResult.Ignore(ex.Message);
                        suiteResult.StackTrace = ex.StackTrace;
                        this.IgnoreReason      = ex.Message;
                    }
                    else
                    {
                        if (IsAssertException(ex))
                        {
                            suiteResult.Failure(ex.Message, ex.StackTrace, FailureSite.SetUp);
                        }
                        else
                        {
                            suiteResult.Error(ex, FailureSite.SetUp);
                        }
                    }
                }
            }
        }
		public void SetResult_Ignore()
		{
			TestSuiteTreeNode node = new TestSuiteTreeNode( testCaseInfo );
			TestResult result = new TestResult( testCaseInfo );

			result.Ignore( "reason" );
			node.Result = result;
			Assert.AreEqual( "MockTest1", node.Result.Name );
			Assert.AreEqual( TestSuiteTreeNode.IgnoredIndex, node.ImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.IgnoredIndex, node.SelectedImageIndex );
			Assert.AreEqual( "Ignored", node.StatusText );
		}
        public void ProcessException(Exception exception, TestResult testResult)
        {
            if (exception is NUnitException)
                exception = exception.InnerException;

            if (IsExpectedExceptionType(exception))
            {
                if (IsExpectedMessageMatch(exception))
                {
                    if (exceptionHandler != null)
                        Reflect.InvokeMethod(exceptionHandler, testMethod.Fixture, exception);

                    testResult.Success();
                }
                else
                {
                    testResult.Failure(WrongTextMessage(exception), GetStackTrace(exception));
                }
            }
            else
            {
                switch (NUnitFramework.GetResultState(exception))
                {
                    case ResultState.Failure:
                        testResult.Failure(exception.Message, exception.StackTrace);
                        break;
                    case ResultState.Ignored:
                        testResult.Ignore(exception);
                        break;
                    case ResultState.Inconclusive:
                        testResult.SetResult(ResultState.Inconclusive, exception, FailureSite.Test);
                        break;
                    case ResultState.Success:
                        testResult.Success(exception.Message);
                        break;
                    default:
                        testResult.Failure(WrongTypeMessage(exception), GetStackTrace(exception));
                        break;
                }
            }
		}
Beispiel #14
0
 private void IgnoreAllTests(TestResult suiteResult, EventListener listener, ITestFilter filter)
 {
     suiteResult.Ignore(this.IgnoreReason);
     MarkTestsNotRun(this.Tests, ResultState.Ignored, this.IgnoreReason, suiteResult, listener, filter);
 }
		/// <summary>
		/// Performs a one-time set-up for this test suite.
		/// </summary>
		/// <remarks>
		/// The implementation calls the base method and then calls all methods decorated
		/// with NUnit's Test Fixture Set Up Attribute that accept a single argument parameter.
		/// </remarks>
		/// <param name="suiteResult">The result of the test.</param>
		protected override void DoOneTimeSetUp(TestResult suiteResult)
		{
			base.DoOneTimeSetUp(suiteResult);
			try
			{
				if (Argument != null)
				{
					foreach (MethodInfo setupMethod in Reflect.GetMethodsWithAttribute(FixtureType, NUnitFramework.FixtureSetUpAttribute, true))
					{
						if (setupMethod.GetParameters().Length == 1)
						{
							Reflect.InvokeMethod(setupMethod, this.Fixture, Argument);
						}
					}
				}
			}
			catch (Exception innerException)
			{
				if (innerException is NUnitException || innerException is TargetInvocationException)
				{
					innerException = innerException.InnerException;
				}

				if (innerException is InvalidTestFixtureException)
				{
					suiteResult.Invalid(innerException.Message);
				}
				else
				{
					if (this.IsIgnoreException(innerException))
					{
						base.RunState = RunState.Ignored;
						suiteResult.Ignore(innerException.Message);
						suiteResult.StackTrace = innerException.StackTrace;
						base.IgnoreReason = innerException.Message;
					}
					else
					{
						if (this.IsAssertException(innerException))
						{
							suiteResult.Failure(innerException.Message, innerException.StackTrace, FailureSite.SetUp);
						}
						else
						{
							suiteResult.Error(innerException, FailureSite.SetUp);
						}
					}
				}
			}
		}
Beispiel #16
0
        public override TestResult Run(EventListener listener, ITestFilter filter)
        {
            using (new TestContext())
            {
                TestResult testResult = new TestResult(this);

                log.Debug("Test Starting: " + this.TestName.FullName);
                listener.TestStarted(this.TestName);
                long startTime = DateTime.Now.Ticks;

                switch (this.RunState)
                {
                    case RunState.Runnable:
                    case RunState.Explicit:
                        Run(testResult);
                        break;
                    case RunState.Skipped:
                    default:
                        testResult.Skip(IgnoreReason);
                        break;
                    case RunState.NotRunnable:
                        if (BuilderException != null)
                            testResult.Invalid(BuilderException);
                        else
                            testResult.Invalid(IgnoreReason);
                        break;
                    case RunState.Ignored:
                        testResult.Ignore(IgnoreReason);
                        break;
                }

                long stopTime = DateTime.Now.Ticks;
                double time = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond;
                testResult.Time = time;

                listener.TestFinished(testResult);
                return testResult;
            }
        }
Beispiel #17
0
 private void IgnoreAllTests(TestResult suiteResult, EventListener listener, ITestFilter filter)
 {
     suiteResult.Ignore(this.IgnoreReason);
     MarkTestsNotRun(this.Tests, ResultState.Ignored, this.IgnoreReason, suiteResult, listener, filter);
 }
Beispiel #18
0
        protected virtual void DoOneTimeSetUp(TestResult suiteResult)
        {
            if (FixtureType != null)
            {
                try
                {
                    if (Fixture == null) // In case TestFixture was created with fixture object
                        CreateUserFixture();

                    if (this.fixtureSetUp != null)
                        Reflect.InvokeMethod(fixtureSetUp, Fixture);
                }
                catch (Exception ex)
                {
                    if (ex is NUnitException || ex is System.Reflection.TargetInvocationException)
                        ex = ex.InnerException;

                    if (IsIgnoreException(ex))
                    {
                        this.RunState = RunState.Ignored;
                        suiteResult.Ignore(ex.Message);
                        suiteResult.StackTrace = ex.StackTrace;
                        this.IgnoreReason = ex.Message;
                    }
                    else
                    {
                        if (IsAssertException(ex))
                            suiteResult.Failure(ex.Message, ex.StackTrace, FailureSite.SetUp);
                        else
                            suiteResult.Error(ex, FailureSite.SetUp);
                    }
                }
            }
        }
		protected void RecordException( Exception ex, TestResult testResult )
		{
			if ( IsIgnoreException( ex ) )
				testResult.Ignore( ex.Message );
			else if ( IsAssertException( ex ) )
				testResult.Failure( ex.Message, ex.StackTrace );
			else	
				testResult.Error( ex );
		}
Beispiel #20
0
        protected virtual void DoOneTimeSetUp(TestResult suiteResult)
        {
            if (FixtureType != null)
            {
                try
                {
					// In case TestFixture was created with fixture object
					if (Fixture == null && !IsStaticClass( FixtureType ) )
						CreateUserFixture();

                    if (this.fixtureSetUpMethods != null)
                        foreach( MethodInfo fixtureSetUp in fixtureSetUpMethods )
                            Reflect.InvokeMethod(fixtureSetUp, fixtureSetUp.IsStatic ? null : Fixture);

                    TestExecutionContext.CurrentContext.Update();
                }
                catch (Exception ex)
                {
                    if (ex is NUnitException || ex is System.Reflection.TargetInvocationException)
                        ex = ex.InnerException;

                    if (ex is InvalidTestFixtureException)
                        suiteResult.Invalid(ex.Message);
                    else if (IsIgnoreException(ex))
                    {
                        this.RunState = RunState.Ignored;
                        suiteResult.Ignore(ex.Message);
                        suiteResult.StackTrace = ex.StackTrace;
                        this.IgnoreReason = ex.Message;
                    }
                    else if (IsAssertException(ex))
                        suiteResult.Failure(ex.Message, ex.StackTrace, FailureSite.SetUp);
                    else
                        suiteResult.Error(ex, FailureSite.SetUp);
                }
            }
        }
		private TestResult SkipTest()
		{
			TestResult testResult = new TestResult(this);
			
            switch (this.RunState)
            {
                case RunState.Skipped:
                default:
                    testResult.Skip(IgnoreReason);
                    break;
                case RunState.NotRunnable:
                    if (BuilderException != null)
                        testResult.Invalid(BuilderException);
                    else
                        testResult.Invalid(IgnoreReason);
                    break;
                case RunState.Ignored:
                    testResult.Ignore(IgnoreReason);
                    break;
            }
			
			return testResult;
		}
Beispiel #22
0
        protected virtual void DoOneTimeBeforeTestSuiteActions(TestResult suiteResult)
        {
            try
            {
                ExecuteActions(ActionPhase.Before);
                TestExecutionContext.CurrentContext.Update();
            }
            catch (Exception ex)
            {
                if (ex is NUnitException || ex is System.Reflection.TargetInvocationException)
                    ex = ex.InnerException;

                if (ex is InvalidTestFixtureException)
                    suiteResult.Invalid(ex.Message);
                else if (IsIgnoreException(ex))
                {
                    this.RunState = RunState.Ignored;
                    suiteResult.Ignore(ex.Message);
                    suiteResult.StackTrace = ex.StackTrace;
                    this.IgnoreReason = ex.Message;
                }
                else if (IsAssertException(ex))
                    suiteResult.Failure(ex.Message, ex.StackTrace, FailureSite.SetUp);
                else
                    suiteResult.Error(ex, FailureSite.SetUp);
            }
        }