protected internal virtual void ProcessException(Exception exception, TestCaseResult testResult) { if (!ExceptionExpected) { RecordException(exception, testResult); return; } if (IsExpectedExceptionType(exception)) { if (IsExpectedMessageMatch(exception)) { if (exceptionHandler != null) { Reflect.InvokeMethod(exceptionHandler, this.Fixture, exception); } testResult.Success(); } else { testResult.Failure(WrongTextMessage(exception), GetStackTrace(exception)); } } else if (IsAssertException(exception)) { testResult.Failure(exception.Message, exception.StackTrace); } else { testResult.Failure(WrongTypeMessage(exception), GetStackTrace(exception)); } }
protected override internal void ProcessException(Exception exception, TestCaseResult testResult) { if (expectedException.Equals(exception.GetType())) { if (expectedMessage != null && !expectedMessage.Equals(exception.Message)) { string message = string.Format("Expected exception to have message: \"{0}\" but received message \"{1}\"", expectedMessage, exception.Message); testResult.Failure(message, exception.StackTrace); } else { testResult.Success(); } } else if (exception is Framework.AssertionException) { RecordException(exception, testResult); } else { string message = "Expected: " + expectedException.Name + " but was " + exception.GetType().Name; testResult.Failure(message, exception.StackTrace); } return; }
protected override internal void ProcessException(Exception exception, TestCaseResult testResult) { if (expectedException.Equals(exception.GetType())) { if (expectedMessage != null && !expectedMessage.Equals(exception.Message)) { string message = string.Format("Expected exception to have message: \"{0}\" but received message \"{1}\"", expectedMessage, exception.Message); testResult.Failure(message, exception.StackTrace); } else { testResult.Success(); } } else if (exception is Framework.AssertionException) { RecordException(exception,testResult); } else { string message = "Expected: " + expectedException.Name + " but was " + exception.GetType().Name; testResult.Failure(message, exception.StackTrace); } return; }
protected internal virtual void ProcessNoException(TestCaseResult testResult) { if (ExceptionExpected) { testResult.Failure(NoExceptionMessage(), null); } else { testResult.Success(); } }
public void ClearResult() { TestCaseResult result = new TestCaseResult( testCaseInfo ); result.Failure("message", "stacktrace"); TestSuiteTreeNode node = new TestSuiteTreeNode( result ); Assert.AreEqual( TestSuiteTreeNode.FailureIndex, node.ImageIndex ); Assert.AreEqual( TestSuiteTreeNode.FailureIndex, node.SelectedImageIndex ); node.ClearResult(); Assert.AreEqual( null, node.Result ); Assert.AreEqual( TestSuiteTreeNode.InitIndex, node.ImageIndex ); Assert.AreEqual( TestSuiteTreeNode.InitIndex, node.SelectedImageIndex ); }
//private TestCaseResult testCase; private TestSuiteResult MockSuiteResult( bool failure ) { TestCaseResult testCaseResult = new TestCaseResult("a test case"); if ( failure ) testCaseResult.Failure( "case failed", null ); TestSuiteResult level1SuiteA = new TestSuiteResult("level 1 A"); level1SuiteA.AddResult(testCaseResult); TestSuiteResult level1SuiteB = new TestSuiteResult("level 1 B"); level1SuiteB.AddResult(new TestCaseResult("a successful test")); TestSuiteResult result = new TestSuiteResult("base"); result.AddResult(level1SuiteA); result.AddResult(level1SuiteB); return result; }
public override void Run(TestCaseResult result) { if (ShouldRun) { DateTime start = DateTime.Now; try { List<string> expectedLines = CreateStringList(WomDocument.Parse(_expected)); WomDocument parseResult = ParseWikiText(_source); List<string> actualLines = CreateStringList(parseResult); CompareStringLists(expectedLines, actualLines); result.Success(); } catch (Exception ex) { if (ex is NunitException) { ex = ex.InnerException; } if (testFramework.IsIgnoreException(ex)) { result.NotRun(BuildMessage(ex), BuildStackTrace(ex)); } else { result.Failure(BuildMessage(ex), BuildStackTrace(ex)); } } finally { DateTime stop = DateTime.Now; TimeSpan span = stop.Subtract(start); result.Time = (double)span.Ticks / (double)TimeSpan.TicksPerSecond; } } else { result.NotRun(this.IgnoreReason); } }
protected void RecordException(Exception exception, TestCaseResult testResult, bool inTearDown) { StringBuilder msg = new StringBuilder(); StringBuilder st = new StringBuilder(); if (inTearDown) { msg.Append(testResult.Message); msg.Append(Environment.NewLine); msg.Append("TearDown : "); st.Append(testResult.StackTrace); st.Append(Environment.NewLine); st.Append("--TearDown"); st.Append(Environment.NewLine); } msg.Append(BuildMessage(exception)); st.Append(BuildStackTrace(exception)); testResult.Failure(msg.ToString(), st.ToString()); }
public override void Run(TestCaseResult testResult) { if (ShouldRun) { bool needParentTearDown = false; try { if (Parent != null) { if (Parent.SetUpNeeded) { Parent.DoOneTimeSetUp(testResult); needParentTearDown = Parent.SetUpComplete; } if (Parent.SetUpFailed) testResult.Failure("TestFixtureSetUp Failed", testResult.StackTrace); } if (!testResult.IsFailure) doRun(testResult); } catch (Exception ex) { if (ex is NunitException) ex = ex.InnerException; RecordException(ex, testResult); } finally { if (needParentTearDown) Parent.DoOneTimeTearDown(testResult); } } else { testResult.NotRun(IgnoreReason); } }
private void MarkTestFailed( Test test, TestSuiteResult suiteResult, EventListener listener, ITestFilter filter) { if (test is TestSuite) { listener.SuiteStarted(test.TestName); TestSuiteResult result = new TestSuiteResult(new TestInfo(test), test.TestName.FullName); string msg = string.Format("Parent SetUp failed in {0}", this.FixtureType.Name); result.Failure(msg, null, FailureSite.Parent); MarkTestsFailed(test.Tests, suiteResult, listener, filter); suiteResult.AddResult(result); listener.SuiteFinished(result); } else { listener.TestStarted(test.TestName); TestCaseResult result = new TestCaseResult(new TestInfo(test)); string msg = string.Format("TestFixtureSetUp failed in {0}", this.FixtureType.Name); result.Failure(msg, null, FailureSite.Parent); suiteResult.AddResult(result); listener.TestFinished(result); } }
public void SetResult_Failure() { TestSuiteTreeNode node = new TestSuiteTreeNode( testCaseInfo ); TestCaseResult result = new TestCaseResult( testCaseInfo ); result.Failure("message", "stacktrace"); node.Result = result; Assert.AreEqual( TestSuiteTreeNode.FailureIndex, node.ImageIndex ); Assert.AreEqual( TestSuiteTreeNode.FailureIndex, node.SelectedImageIndex ); Assert.AreEqual( "Failure", node.StatusText ); }
protected override internal void ProcessNoException(TestCaseResult testResult) { testResult.Failure(expectedException.Name + " was expected", null); }
private void MarkTestFailed( Test test, TestSuiteResult suiteResult, EventListener listener, ITestFilter filter) { if (test is TestSuite) { listener.SuiteStarted(test.TestName); TestSuiteResult result = new TestSuiteResult( new TestInfo(test), test.TestName.FullName); string msg = string.Format( "Parent SetUp failed in {0}", this.FixtureType.Name ); result.Failure(msg, null, FailureSite.Parent); MarkTestsFailed(test.Tests, suiteResult, listener, filter); suiteResult.AddResult(result); listener.SuiteFinished(result); } else { listener.TestStarted(test.TestName); TestCaseResult result = new TestCaseResult( new TestInfo(test) ); string msg = string.Format( "TestFixtureSetUp failed in {0}", this.FixtureType.Name ); result.Failure(msg, null, FailureSite.Parent); suiteResult.AddResult(result); listener.TestFinished(result); } }
protected internal virtual void ProcessException(Exception exception, TestCaseResult testResult) { if (!ExceptionExpected) { RecordException(exception, testResult); return; } if (IsExpectedExceptionType(exception)) { if (IsExpectedMessageMatch(exception)) { if ( exceptionHandler != null ) Reflect.InvokeMethod( exceptionHandler, this.Fixture, exception ); testResult.Success(); } else { testResult.Failure(WrongTextMessage(exception), GetStackTrace(exception)); } } else if (IsAssertException(exception)) { testResult.Failure(exception.Message, exception.StackTrace); } else { testResult.Failure(WrongTypeMessage(exception), GetStackTrace(exception)); } }
protected internal virtual void ProcessNoException(TestCaseResult testResult) { if ( ExceptionExpected ) testResult.Failure(NoExceptionMessage(), null); else testResult.Success(); }
protected void RecordException( Exception exception, TestCaseResult testResult, bool inTearDown ) { StringBuilder msg = new StringBuilder(); StringBuilder st = new StringBuilder(); if ( inTearDown ) { msg.Append( testResult.Message ); msg.Append( Environment.NewLine ); msg.Append( "TearDown : " ); st.Append( testResult.StackTrace ); st.Append( Environment.NewLine ); st.Append( "--TearDown" ); st.Append( Environment.NewLine ); } msg.Append( BuildMessage( exception ) ); st.Append( BuildStackTrace( exception ) ); testResult.Failure( msg.ToString(), st.ToString() ); }
public bool Run(TestInfo test, TestSuiteResult suite_result, string test_name, EventListener listener, ITestFilter filter, int timeout) { listener = new ProxyListener (listener); TestRunnerDelegate runner = new TestRunnerDelegate (delegate { return server.Run (test_name, listener, filter); }); IAsyncResult ar = runner.BeginInvoke (test_name, null, filter, null, null); if (!ar.AsyncWaitHandle.WaitOne (timeout) || !ar.IsCompleted) { TestCaseResult error = new TestCaseResult (test); string msg = String.Format ("Timeout after {0} ms", timeout); error.Failure (msg, null, FailureSite.Parent); suite_result.AddResult (error); return false; } try { TestResult result = runner.EndInvoke (ar); if (result != null) { suite_result.AddResult (result); return true; } TestCaseResult error = new TestCaseResult (test); error.Failure ("Unknown error", null, FailureSite.Parent); suite_result.AddResult (error); return false; } catch (Exception ex) { TestCaseResult error = new TestCaseResult (test); string msg = String.Format ("Unknown exception: {0}", ex); error.Failure (msg, null, FailureSite.Parent); suite_result.AddResult (error); return false; } }
public override TestResult Run(EventListener listener, ITestFilter filter) { TestSuiteResult suite_result = new TestSuiteResult (new TestInfo (this), TestName.FullName); DebuggerTestHost host = DebuggerTestHost.Create (); if (host == null) { TestCaseResult error = new TestCaseResult (new TestInfo (this)); string msg = String.Format ("Failed to create DebuggerTestHost in {0}", FixtureType.Name); error.Failure (msg, null, FailureSite.Parent); suite_result.AddResult (error); return suite_result; } int timeout; if (Attribute.Timeout != 0) timeout = Attribute.Timeout; else timeout = DebuggerTestAddIn.DefaultTimeout; int repeat = 1; if (Attribute.Repeat != 0) repeat = Attribute.Repeat; try { for (int i = 0; i < repeat; i++) { if (!host.Run (new TestInfo (this), suite_result, Type.AssemblyQualifiedName, listener, filter, timeout)) break; } return suite_result; } finally { host.Dispose (); } }
public override void Run (TestCaseResult res) { string type = _test.GetAttribute ("TYPE"); if (type == "error") res.Success (); Uri baseUri = new Uri (_test.BaseURI); Uri testUri = new Uri (baseUri, _test.GetAttribute ("URI")); bool nonValidatingPassed = TestNonValidating (testUri.ToString ()); bool validatingPassed = TestValidating (testUri.ToString ()); bool isok = isOK (type, nonValidatingPassed, validatingPassed); string message=""; if (_inverseResult) { isok = !isok; message = "The following test was FIXED:\n"; } if (isok) res.Success (); else { message += "type:"+type; message += " non-validating passed:"+nonValidatingPassed.ToString(); message += " validating passed:"+validatingPassed.ToString(); message += " description:"+_test.InnerText; res.Failure (message, _errorString); } }
void ReportResult (string failureMessage, string stackTrace, TestCaseResult res) { if (_inverseResult) { if (failureMessage != null) res.Success (); else res.Failure ("The following test was FIXED: "+_testid, null); } else { if (failureMessage != null) res.Failure (failureMessage, stackTrace); else res.Success (); } }
private TestSuiteResult MockSuiteResult(string suiteName, bool failure) { TestSuiteResult result = new TestSuiteResult(suiteName); result.Time = time; result.RunState = RunState.Executed; TestSuiteResult level1SuiteA = new TestSuiteResult("level 1 A"); result.AddResult(level1SuiteA); level1SuiteA.RunState = RunState.Executed; TestSuiteResult level1SuiteB = new TestSuiteResult("level 1 B"); result.AddResult(level1SuiteB); level1SuiteB.RunState = RunState.Executed; testCase = new TestCaseResult("a test case"); if(failure) testCase.Failure("argument exception",null); else testCase.Success(); level1SuiteA.AddResult(testCase); testCase = new TestCaseResult("a successful test"); testCase.Success(); level1SuiteB.AddResult(testCase); testCase = new TestCaseResult("a not run test"); testCase.Ignore("test not run"); level1SuiteB.AddResult(testCase); return result; }
public override void Run (TestCaseResult res) { try { Harness.RunSingleTest(_baseUrl, _testInfo); } catch (Exception e) { res.Failure(e.Message, null); return; } res.Success(); }
protected override internal void ProcessNoException(TestCaseResult testResult) { testResult.Failure(expectedException.Name + " was expected", null); }