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

Introduce @WithTestResource as an analogous to @QuarkusTestResource(restrictAnnotatedClass=true) #37853

Closed
edeandrea opened this issue Dec 19, 2023 · 16 comments · Fixed by #41368
Labels
area/testing kind/enhancement New feature or request
Milestone

Comments

@edeandrea
Copy link
Contributor

Description

This is spawned from this thread - https://twitter.com/cowtowncoder/status/1736913697426338262

In the next major version of Quarkus (where we can make breaking changes) we should default restrictAnnotatedClass on the QuarkusTestResource annotation to true.

Implementation ideas

No response

Copy link

quarkus-bot bot commented Dec 19, 2023

/cc @geoand (testing)

@maxandersen
Copy link
Member

I admit that reading the thread the default surprised me too and the attribute name is quite long vs for example just global=true|false.

So I grok the wish/request.

4.0 is not even planned yet except we know it's not happening anytime soon.

My question/concern is how big a breakage this will be and how many users will have to add restrictToAnnotatedClass=false to make their tests pass.

I do assume we can handle it in quarkus update but it's still problematic if everyone is affected.

Are there better alternatives?

  • Deprecate the current and Introduce a new annotation with better defaults? Advantages: we don't break anyone and we can have @Deprecation notice stating the solution and update all docs to use the new. Disadvantage: an extra annotation

  • Do the default change but have package level annotation or even config property to switch default ? Advantages: does not require users to change all their test code to try out 4.0. Disadvantage: I think we generally prefer to not have annotation behaviors encoded in config)

@geoand
Copy link
Contributor

geoand commented Dec 20, 2023

My question/concern is how big a breakage this will be and how many users will have to add restrictToAnnotatedClass=false to make their tests pass.

It could easily result in most tests of a testsuite failing

I think we generally prefer to not have annotation behaviors encoded in config)

Indeed

@geoand
Copy link
Contributor

geoand commented Dec 20, 2023

Another alternative would be to use a new annotation and deprecate the existing one

@Sanne
Copy link
Member

Sanne commented Dec 20, 2023

Another alternative would be to use a new annotation and deprecate the existing one

+1

I don't think it's a good idea to defer such changes to a "major release", unless there's no alternative:

  • it leads to piling up changes which need to be performed in a very specific, possibly short time frame
  • it would need specific processes: who's keeping track of us not missing all the issues which need to happen when the next major is planned
  • even for a major release, would be best to avoid breaking changes or at least have a nice migration path
  • it defers improvements indefinitely

@edeandrea
Copy link
Contributor Author

I agree with what everyone has said here. Not that I'm advocating for keeping the existing annotation, but using something like OpenRewrite would be pretty simple during a quarkus upgrade to keep people's current functionality on the existing annotation (anyone with @QuarkusTestResource without specifically specifying restrictToAnnotatedClass would be re-written to setting restrictToAnnotatedClass = false while anyone with @QuarkusTestResource while specifying restrictToAnnotatedClass set to any value would be left alone).

Deprecating an existing annotation and replacing it with another with all the same properties but just different defaults seems clunky to me.

@geoand is right - it could break an entire test suite, but I think in those cases those people would be of the same realization - that things were working in a way that they didn't know/understand it was working that way. I would venture to guess that the majority of people who specify restrictToAnnotatedClass=true do so because they understand the current behavior and don't want it.

@tqvarnst
Copy link
Contributor

An alternative could be to retain the old behavior with a feature flag in the configuration. For example:

quarkus.testing.default.test-resources.as.global=true #Just a suggestion, feel free to suggest another config key.

With this one set, the default behavior returns to making TestResources global. If not set we restrict to annotated class only.

@geoand
Copy link
Contributor

geoand commented Dec 20, 2023

@tqvarnst, I think that's in effect one of the proposals @maxandersen put forth, but we have generally shied away from allowing such kind of behavioral change via configuration.

@geoand
Copy link
Contributor

geoand commented Jan 9, 2024

The more I think of it, the more I am in favor of introducing a new annotation and deprecating the old one.
Any suggestions for a new name?

@edeandrea
Copy link
Contributor Author

Naming things is hard :) I think QuarkusTestResource is actually quite a good name as it clearly identifies what it does.

How about something like @UseTestResource? More of a verb than a noun.

@geoand
Copy link
Contributor

geoand commented Jan 10, 2024

@UseTestResource or @WithTestResource sound like nice to names to me.

@edeandrea
Copy link
Contributor Author

I like @WithTestResource

@geoand
Copy link
Contributor

geoand commented Jan 10, 2024

Let's also ask @gsmet who is good with naming things

@edeandrea
Copy link
Contributor Author

@geoand any problems with me taking this up?

@geoand
Copy link
Contributor

geoand commented Jun 21, 2024

Yeah, I think adding the new annotation makes sense!

edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 21, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 22, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 22, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 24, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 25, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 25, 2024
edeandrea added a commit to edeandrea/quarkus that referenced this issue Jun 25, 2024
@geoand geoand changed the title Default restrictToAnnotatedClass in @QuarkusTestResource to true in next major version Introduce @WithTestResource as an analogous to @QuarkusTestResource(restrictAnnotatedClass=true) Jun 25, 2024
@geoand
Copy link
Contributor

geoand commented Jun 25, 2024

I updated the title of the issue to reflect the latest status

@geoand geoand closed this as completed in 5717408 Jun 26, 2024
@quarkus-bot quarkus-bot bot added this to the 3.13 - main milestone Jun 26, 2024
holly-cummins pushed a commit to holly-cummins/quarkus that referenced this issue Jul 31, 2024
danielsoro pushed a commit to danielsoro/quarkus that referenced this issue Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants