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
Enclosing classes vs Before/AfterAll #479
Comments
Maybe (obviously) I don't get it: When the two extensions use it correctly then why change them? |
I find it a bit weird that different extensions take two different approaches to achieve the same goal. As I see it, this is not an "it depends" situation - the extensions have the exact same requirements, so one solution should suffice. Maybe one of them is better and we should pick that one, but even if not - having just one eases learning and maintenance. |
Ah okay, thanks for clarification. I agree with you that we should have one approach for the same thing and not multiple |
Does it really matter? Both approaches solve the same problem just in different ways. Personally, I think not implementing |
I found another dimension to this triggered by what @beatngu13 wrote on #496:
Checking the Javadoc, it says:
The last sentences can indeed be easily misunderstood to mean that the property is cleared before each test. And at the moment (i.e. before #496 is merged), the default locale / time zone extensions do behave as the reader of the above text expected and set a value before each test. Then again, this doesn't really work well with manually setting the value (in this case the default locale), either: The class level annotation will store the current default locale before each test and reset it after. If a test sets the default locale manually with As it is now, #496 will make the locale / time zone extensions implement the before/after all extension points, which at least means that the when the extension goes out of scope, it resets the value to the one it was before executing any of the tests and that means the manually set value will be overridden for good. That's a good thing, I think. Now the question is whether we should try to also create that behavior where a class level annotation sets before each test execution - maybe without storing the old value, knowing that the value at the beginning of executing the test class was stored and will eventually be restored? |
Just so it doesn't get overlooked: #496 changes the behavior of default locale / time zone extensions inasmuch that a class-level annotation no longer sets a value before each test, which means if users manually set locales or time zones, their test behavior changes. |
If I understood @nipafx correctly than one way of implementation it will break the extension, while the other way does not? |
We just had a lengthy discussion about what this should means: @CoolExtension
class MyTests {
@Test
void testMethodA() {
// ...
}
@Test
void testMethodB() {
// ...
}
} Namely, is
Technically, the first option is more powerful as it allows more varied behavior (carrying the state from test to test before resetting after all of them is otherwise not possible). Taken together, here's my proposal:
So we will really only have that as a default, individual extensions can always diverge, where it makes sense. |
@beatngu13 Can you update #496 according to my last comment? 😬 |
PR is ready to merge. We need to discuss whether this requires a 2.0 release. It's definitely a "breaking change" in the sense that tests may behave differently afterwards. Then again, this could easily be considered a bug fix ("prevent leaking state from one test to another"). I guess philosophically, since somebody always relies on bugs, fixing those could be considered breaking changes as well. So, really, is there any difference between rewriting an API and fixing a bug? 🤷🏾♂️ 😁 Anybody convinced by that equivocation? Can we release with 1.7? |
If an extension needs to search for enclosing elements, there are basically two ways to do so: 1. Combine `BeforeAllCallback`/`AfterAllCallback` with `BeforeEachCallback`/`AfterEachCallback`. 2. Use`BeforeEachCallback`/`AfterEachCallback` and look up enclosing elements (e.g. via `PioneerAnnotationUtils#findClosestEnclosingAnnotation(...)`). We agreed on approach no. 2 since it appears to be less error-prone and cover more common use cases. This PR aligns the use of extension points to guarantee consistent behavior across different extensions and documents our decision. Closes: #479 PR: #496
In #473/#476 we removed the search for annotations on enclosing classes because it's handled by the Before/AfterAll callbacks. That made me wonder whether there are other extensions that misuse
PioneerAnnotationUtils::findClosestEnclosingAnnotation
. I looked at two extensions:Questions:
The text was updated successfully, but these errors were encountered: