junitquarkusapplication.propertiesquarkus-rest-client

Can I override quarkus application.properties value in my test class?


I have a value configured in my quarkus application.properties

skipvaluecheck=true

Now whenever I want to execute my tests, I want to have this value to be set to false instead of true. But I do not want to change in application.properties because it will affect the latest application deployment. I just want my tests to be executed with value false so that my test coverage goes green in sonar.

From java code, I fetch this value by doing below

ConfigProvider.getConfig().getValue("skipvaluecheck", Boolean.class);

Something similar already exists in Sprint boot and I am curious if such thing also exist in quarkus

Override default Spring-Boot application.properties settings in Junit Test


Solution

  • You need to define an implementation of io.quarkus.test.junit.QuarkusTestProfile and add it to the test via @TestProfile.

    Something like:

    @QuarkusTest
    @TestProfile(MyTest.BuildTimeValueChangeTestProfile.class)
    public class MyTest {
        @Test
        public void testSomething() {
        }
        
        public static class BuildTimeValueChangeTestProfile implements QuarkusTestProfile {
        
            @Override
            public Map<String, String> getConfigOverrides() {
                return Map.of("skipvaluecheck", "true");
            }
        }
    }
    

    See more details can be found here