Merge pull request #77 from twisterino/NUnitTearDownFix

Prevent TearDown to swallow exceptions
This commit is contained in:
Marko Lahma
2014-07-19 11:24:00 +03:00
2 changed files with 56 additions and 16 deletions

View File

@@ -349,6 +349,7 @@ namespace Spring.Testing.NUnit
catch (Exception ex)
{
logger.Error("OnTearDown error", ex);
throw;
}
}

View File

@@ -1,22 +1,24 @@
#region License
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#endregion
using System;
using NUnit.Framework;
using Spring.Context;
@@ -127,5 +129,42 @@ namespace Spring.Testing.NUnit
Assert.AreNotSame(fixtureInstance.ApplicationContext, otherFixtureInstance.ApplicationContext);
otherFixtureInstance.TearDown();
}
}
private class TestAbstractDependencyInjectionSpringContextTestsExceptions : AbstractDependencyInjectionSpringContextTests
{
private static readonly string[] CONFIGLOCATIONS = new string[] { "assembly://Spring.Testing.NUnit.Tests/Spring.Testing.NUnit/TestApplicationContext.xml" };
public TestAbstractDependencyInjectionSpringContextTestsExceptions()
{ }
protected override string[] ConfigLocations
{
get { return CONFIGLOCATIONS; }
}
protected override void OnSetUp()
{
throw new Exception("SetUp Exception");
}
protected override void OnTearDown()
{
throw new Exception("TearDown Exception");
}
}
[Test, ExpectedException]
public void ThrowsSetUpException()
{
var testFixture = new TestAbstractDependencyInjectionSpringContextTestsExceptions();
testFixture.SetUp();
}
[Test, ExpectedException]
public void ThrowsTearDownException()
{
var testFixture = new TestAbstractDependencyInjectionSpringContextTestsExceptions();
testFixture.TearDown();
}
}
}