-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SetUp/TearDown not called recursively for PropertyAttribute #457
Comments
Ah, it looks like you almost have a pull request, hint hint. Is the crux here the recursive part? We already seem to be calling setup and teardown here: https://github.com/fscheck/FsCheck/blob/master/src/FsCheck.NUnit/FsCheckPropertyAttribute.fs#L119 Also do you have an example that doesn't work? I'm just trying to understand what recursive really means in this context...I'm not super-familiar with NUnit. |
:) I might have time to look at this earlier next week
Yes. Each class in the hierarchy is allowed to have
Some pseudocode class Parent {
int setupParent;
int teardownParent;
[SetUp] void SetupParent() { ++setupParent; }
[TearDown] void TeardownParent() { ++teardownParent; }
}
class Child : Parent {
int setupChild;
int teardownChild;
[SetUp] void SetupChild() { ++setupChild; }
[TearDown] void TeardownChild() { ++teardownChild; }
} With the naive implementation, this we get (completely unverified) setupParent = 0
teardownParent = 0
setupChild = 1
teardownChild = 1 So we need to call SetUp starting at the lowest level, Parent, and TearDown starting at the top, Child. Not sure why people haven't noticed, but people might be using virtual/override instead -- we used this ourselves until it became a problem when trying to restart the tests. |
That clarifies things, thank you. A few more things:
If you're careful about when you call Also, wouldn't the code have to check whether the setup/teardown isn't already virtual, otherwise we may be calling the parent's setup/teardown more than once? |
I think our problem was it was being called twice (without double checking this) class Base {
[SetUp] virtual void Setup() {}
}
class Child : Base {
[SetUp] override void Setup() { base.Setup(); }
} I think having I should probably experiment to see exactly what went on here -- I just got a bit eager to get it working that I looked an the NUnit implementation and found out we're probably using it "wrong". |
When using
PropertyAttribute
, I would expect allSetUpAttribute
andTearDownAttribute
to be run as would be the case forTestAttribute
.We have an attribute with a similar use-case, and does the following:
where
The text was updated successfully, but these errors were encountered: