public void HandleExceptionInBothSetUpAndTearDown() { Exception e1 = new Exception("Test message for exception thrown from setup"); Exception e2 = new Exception("Test message for exception thrown from tear down"); SetupAndTearDownExceptionFixture fixture = new SetupAndTearDownExceptionFixture(); fixture.setupException = e1; fixture.tearDownException = e2; ITestResult suiteResult = TestBuilder.RunTestFixture(fixture); Assert.That(suiteResult.HasChildren, "Fixture test should have child result."); ITestResult result = suiteResult.Children.ToArray()[0]; Assert.AreEqual(ResultState.Error, result.ResultState, "Test should be in error state"); string expected = string.Format("{0} : {1}", e1.GetType().FullName, e1.Message) + Environment.NewLine + string.Format("TearDown : {0} : {1}", e2.GetType().FullName, e2.Message); Assert.AreEqual(expected, result.Message); Assert.That(result.StackTrace, Does.Contain("--TearDown")); Assert.That(result.StackTrace, Does.Contain(fixture.GetType().FullName)); // Sanity check }
public void HandleExceptionInTearDown() { Exception e = new Exception("Test message for exception thrown from tear down"); SetupAndTearDownExceptionFixture fixture = new SetupAndTearDownExceptionFixture(); fixture.TearDownException = e; ITestResult suiteResult = TestBuilder.RunTestFixture(fixture); Assert.That(suiteResult.HasChildren, "Fixture test should have child result."); ITestResult result = suiteResult.Children.ToArray()[0]; Assert.AreEqual(ResultState.Error, result.ResultState, "Test should be in error state"); string expected = string.Format("TearDown : {0} : {1}", e.GetType().FullName, e.Message); Assert.AreEqual(expected, result.Message); Assert.That(result.StackTrace, Does.StartWith("--TearDown")); PlatformInconsistency.MonoMethodInfoInvokeLosesStackTrace.SkipOnAffectedPlatform(() => { Assert.That(result.StackTrace, Does.Contain(fixture.GetType().FullName)); // Sanity check }); }