'Quarkus custom test resources dir

We are using multiple source sets for tests in our project which defined in gradle like this:

sourceSets {
    test {
        java {
            srcDir file('src/test/unit/java')
        }
        resources.srcDir file('src/test/unit/resources')
    }
    functionalTest {
        java {
            compileClasspath += main.output
            runtimeClasspath += main.output
            srcDir file('src/test/functional/java')
        }
        resources.srcDir file('src/test/functional/resources')
    }
}

And our app properties file located here: src/test/functional/resources/application-test.yml.

Quarkus doesn't read properties from this location and seems like internally has only main and test paths hardcoded, is there a way to append custom dirs to resources resolution?

We have tried also setting a custom profile to functionalTest or functional-test but it doesn't help either:

@QuarkusTest
@TestProfile(FunctionalTestProfile.class)
class FrontendControllerTest {}

import io.quarkus.test.junit.QuarkusTestProfile;

public class FunctionalTestProfile implements QuarkusTestProfile {

    public String getConfigProfile() {
        return "functionalTest";
    }
}


Solution 1:[1]

We ended up using a custom test profile for functional tests which manually takes and merges resources in same way as quarkus does it internally:

import io.quarkus.config.yaml.runtime.ApplicationYamlConfigSourceLoader;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.smallrye.config.source.yaml.YamlConfigSource;
import org.eclipse.microprofile.config.spi.ConfigSource;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class FunctionalTestProfile implements QuarkusTestProfile {

    @Override
    public Map<String, String> getConfigOverrides() {
        var sources = new ApplicationYamlConfigSourceLoader.InClassPath().getConfigSources(getClass().getClassLoader());
        Collections.reverse(sources);

        var result = new HashMap<String, String>();
        sources.stream()
            .filter(YamlConfigSource.class::isInstance)
            .map(ConfigSource::getProperties)
            .forEach(result::putAll);

        return result;
    }
}

Then in test itself:

@QuarkusTest
@TestProfile(FunctionalTestProfile.class)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sam Ivichuk