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

QuarkusTest: consider removing the test profile support for @Nested tests #45349

Open
mkouba opened this issue Jan 3, 2025 · 8 comments · May be fixed by #34681
Open

QuarkusTest: consider removing the test profile support for @Nested tests #45349

mkouba opened this issue Jan 3, 2025 · 8 comments · May be fixed by #34681

Comments

@mkouba
Copy link
Contributor

mkouba commented Jan 3, 2025

Currently, it is possible to specify a test profile for a @Nested test (inner class of a top-level test class). However, this may cause troubles if the enclosing test class defines a different test profile; i.e. the enclosing class should be tested against a different application build. Keep in mind that Quarkus always needs to obtain the instance of the enclosing test class from the CDI container.

More specifically, if a CDI bean Foo is only enabled in the profile FooProfile then it cannot be injected in the test class FooTest because it would cause unsatisfied dependency in the test class FooTest$FooNested:

@TestProfile(FooProfile.class) // -> enables Foo
public class FooTest {
   
    @Inject Foo foo; // this is legal and works fine when FooTest#test() is run

    void test() {
       // ...
    }

   @Nested
   @TestProfile(FooNestedProfile.class) // -> Foo is not enabled here
   class FooNested {
     
      void test() {
         // ...this test always fails because when the test app is built FooTest#foo results in an unsatisfied dependency
      } 
     
   }

}
@mkouba
Copy link
Contributor Author

mkouba commented Jan 3, 2025

Copy link

quarkus-bot bot commented Jan 3, 2025

/cc @geoand (testing)

mkouba added a commit to mkouba/quarkus that referenced this issue Jan 3, 2025
- note that we cannot veto test classes that contain a matching nested
  test; we should probably drop the test profile support for nested tests, see quarkusio#45349
- fixes quarkusio#45308
@geoand
Copy link
Contributor

geoand commented Jan 3, 2025

@holly-cummins didn't you run into something similar?

@mkouba
Copy link
Contributor Author

mkouba commented Jan 3, 2025

@holly-cummins didn't you run into something similar?

There was a discussion on zulip in the "WG 30 Test Classloading chatter" channel: https://quarkusio.zulipchat.com/#narrow/channel/187038-dev/topic/WG.20.2330.20Test.20Classloading.20chatter/near/484875724

@geoand
Copy link
Contributor

geoand commented Jan 3, 2025

In any case, +1

@manovotn
Copy link
Contributor

manovotn commented Jan 3, 2025

Same here, +1

@holly-cummins
Copy link
Contributor

I ended up doing this as part of #34681 (not yet merged, and huge). I'm happy to see another reason to do it.

I'll mark this as resolved by that PR for now, but I might split it out and ship it earlier, in the interests of small changes.

@manovotn
Copy link
Contributor

manovotn commented Jan 7, 2025

I ended up doing this as part of #34681 (not yet merged, and huge). I'm happy to see another reason to do it.

I'll mark this as resolved by that PR for now, but I might split it out and ship it earlier, in the interests of small changes.

Awesome, thank you! :)

@holly-cummins holly-cummins moved this from Todo to In Progress in WG - Test classloading Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

4 participants