quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.64k stars 2.64k forks source link

Inconsistent config behavior across Quarkus nested tests #39229

Open gbourant opened 7 months ago

gbourant commented 7 months ago

Describe the bug

I'm writing nested tests for my Quarkus main method. In each nested test i override the config but the problem is that other tests see the changed config when it shouldn't.

In the following class the MainTest#testMain and Inner2Test#testMain work as expected but the Inner#testMain fails since the Inner2Test change the config.

If you run each individual test from the IDE they do work, in order to reproduce it you have to run the whole test (MainTest.java) or simple run mvn test.

I have created a reproducer here.

@QuarkusMainTest
class MainTest {

    @Nested
    @TestProfile(Inner.MyTestProfile.class)
    class Inner {

        public static class MyTestProfile implements QuarkusTestProfile {
        }

        @Test
        @Launch(value = {}, exitCode = 0)
        public void testMain() {
        }
    }
    @Nested
    @TestProfile(Inner2Test.MyTest2Profile.class)
    class Inner2Test {

        public static class MyTest2Profile implements QuarkusTestProfile {

            @Override
            public Map<String, String> getConfigOverrides() {
                return Map.of("project.required", "false");
            }

        }

        @Test
        @Launch(value = {}, exitCode = 1000)
        public void testMain() {
        }
    }

    @Test
    @Launch(value = {}, exitCode = 0)
    public void testMain() {
    }
}

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

gbourant commented 7 months ago

After further investigation, the problem is not just in the getConfigOverrides but it expands to the getEnabledAlternatives method (maybe other methods too ?).

It seems that when a class implements QuarkusTestProfile which overrides the default values (getEnabledAlternatives/getConfigOverrides/etc) they are not isolated to the current test but they are visible to other tests.

gbourant commented 3 months ago

If i put each nested class to each own file then the tests are working fine, it has nothing to do with getConfigOverrides or getEnabledAlternatives rather than @Nested.