简体   繁体   中英

Gradle + Spring Boot - how can I read resources in “itest” sourceSet in a test in “test” sourceSet

I have sourceSet itest , test and main at the save level.

In a test in test sourceSet, I want to read a text file in itest/resources . Is that possible?

Yes, I have found the way.

Just change sourceSet test configuration: modify resources.srcDirs to add another path to the value set.

In build.gradle :

sourceSets {
    test {
        output.resourcesDir = "build/resources/test" // copy test resources to build 
        resources.srcDirs = ['src/test/resources', 'src/itest/resources/fixtures/preAuthMock2']
        // to include example json from itest resources
    }
}

Note that when you specify this folder which is the direct parent dir of the file you need, when you read the file with getResourceAsStream() , you only need /foo.json as the path, instead of /fixtures/preAuthMock2/foo.json .

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