Skip to content
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

Support specifying when @BeforePropety is invoked in relation to hooks #395

Closed
adam-waldenberg opened this issue Oct 20, 2022 · 6 comments
Closed

Comments

@adam-waldenberg
Copy link

Testing Problem

There doesn't seem to be a way to control if @BeforeProperty methods should be invoked before or after hooks. At first, I thought the proximity influenced this, but this does not seem to affect anything else than how hooks are executed in relation to each other.

Suggested Solution

Maybe add a @BeforePropertty(beforeHooks=true/false). Alternatively add a "proximity" to when methods with these annotations are executed and then allow the hooks to work around them by setting proximity().

@jlink
Copy link
Collaborator

jlink commented Oct 21, 2022

Well, in theory (I just checked the code), the proximity of any AroundPropertyHook should influence the behaviour.
Methods annotated with @BeforeProperty run with a proximity of -10. So if your hook should run after @BeforeProperty methods the proximity should be > -10, and respectively < -10 to run before.

I extended the tests to make that clear: https://github.com/jlink/jqwik/blob/main/engine/src/test/java/net/jqwik/engine/execution/lifecycle/LifecycleMethodsTests.java
So I'd say that the documentation of aroundPropertyProximity() is correct.

That said, it could be a new feature to influence the proximity of individual before/after methods through an attribute in @BeforeProperty and @AfterProperty. This would require a larger change in the implementation, though.

@jlink
Copy link
Collaborator

jlink commented Oct 22, 2022

I assume I could answer your question. If not, please re-open the issue.

@jlink jlink closed this as completed Oct 22, 2022
@adam-waldenberg
Copy link
Author

Aha. Thanks @jlink. I completely missed this. It will do for now!

However, I agree that it would probably be useful to be able to influence this on a per-test basis.

@jlink
Copy link
Collaborator

jlink commented Oct 24, 2022

Would ˋAddLifecycleHook(value=HookClass.class, proximity = 100)ˋ do?

@adam-waldenberg
Copy link
Author

Yeah... That would work. I think it would also make it clearer in showing in what order things fire if it had the default for that property set as referenced in the documentation in your previous comment.

One case to consider would be if the hook is defined on the class rather than per-method and how one overrides the other. I guess whenever that fine grained control is needed, it's not the end of the world to have to define it for each method though.

@jlink
Copy link
Collaborator

jlink commented Oct 25, 2022

@adam-waldenberg As described in #398 it's not as simple as I originally thought it could be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants