Reputation: 21194
I want to create a log statement whenever all tests in a project have been successful. For that I created a [OneTimeTearDown]
method on the project's SetUpFixture class. I'm wondering now how to obtain the overall test results from there.
Behind the scenes: I want to check in an external system whether this project's tests have been run successfully and the connection to the external system is easily available from within the tests, which is why a solution with the OneTimeTearDown would be very cheap to implement.
Upvotes: 0
Views: 245
Reputation: 1237
using NUnit.Framework;
using NUnit.Framework.Interfaces;
namespace Tests {
[TestFixture] internal class Playground {
[OneTimeTearDown] public void OneTimeTearDown() {
if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed) {
// one ore more tests in this fixture failed
}
}
[TearDown] public void TearDown() {
if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed) {
// current test failed
}
}
[Test] public void GoodTest() {
Assert.IsTrue(true);
}
[Test] public void BadTest() {
Assert.IsTrue(false);
}
}
}
Upvotes: 0