11

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

Sandra
  • 419
  • 7
  • 17

4 Answers4

15

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.MyProfile.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

JHoerbst
  • 918
  • 9
  • 17
geoand
  • 60,071
  • 24
  • 172
  • 190
4

Quarkus provides the use of a QuarkusTestProfile for this, you can define a profile like so:

public class CustomTestProfile implements QuarkusTestProfile {

    Map<String, String> getConfigOverrides() {
        return Map.of("skipvaluecheck", "false");
    }

}

Then on your test class:

@QuarkusTest
@TestProfile(CustomTestProfile.class)
public class TestClass {
//...(etc)...

More info available here: https://quarkus.io/blog/quarkus-test-profiles/

Michael Berry
  • 70,193
  • 21
  • 157
  • 216
1

Quarkus application properties have profiles. e.g.

quarkus.log.level=WARN
%test.quarkus.log.level=INFO

That way (with prefix %test.) you can set a different value for testing instead of the production value. You can also set %dev. for when you're running in local dev mode.

See https://quarkus.io/guides/config-reference#profiles for reference.

0

You can make an application-test.yaml file where you specify those properties you want to override. You must place it in the same folder as your default application.yaml (that you must have, even if it is empty) I'm referring to this ticket: https://github.com/quarkusio/quarkus/issues/24900 If you use @QuarkusTest annotation on your tests it will use "test" profile by default.

Viktor Korai
  • 177
  • 2
  • 13