简体   繁体   中英

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";
    }
}

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM