-
Notifications
You must be signed in to change notification settings - Fork 163
Open
Labels
Description
When using PropertyAttribute, I would expect all SetUpAttribute and TearDownAttribute to be run as would be the case for TestAttribute.
We have an attribute with a similar use-case, and does the following:
// We need to manually clean up the test before trying again.
// I was unable to reuse existing NUnit functionality for this.
//
// See also NUnits SimpleWorkItem and RetryCommand
TestFixture fixture;
{
var p = context.CurrentTest.Parent;
while (!(p is TestFixture)) p = p.Parent;
fixture = (TestFixture) p;
}
var teardownMethods = fixture.TearDownMethods.OrderByDescending(GetTypeDepth);
foreach (var m in teardownMethods)
{
try
{
m.Invoke(context.TestObject, new object[] { });
}
catch
{
// Has teardown already completed?
// We just ignore all errors and assume a full setup will solve all problems
}
}
var setupMethods = fixture.SetUpMethods.OrderBy(GetTypeDepth);
foreach (var m in setupMethods)
{
m.Invoke(context.TestObject, new object[] { });
}where
private static int GetTypeDepth(MethodInfo x)
{
var d = 0;
for (var ty = x.DeclaringType; ty != null; ty = ty.BaseType)
{
++d;
}
return d;
}