My plugin needs to load credentials from property files. What is the best way to load the gradle properties when testing a plugin, the way Gradle would load them if I executed the project normally? For example, I have this code:
class PluginSpec extends Specification {
Project project = ProjectBuilder.builder().build()
def "test my plugin"() {
project.apply plugin: "myplugin"
// I am not sure this is the right way to emulate the real operation
Properties props = new Properties()
props.load(new FileInputStream(System.getProperty("user.home")+"/.gradle/gradle.properties"))
}
}
Can you help me find examples of setting up the project instance with properties when testing?
Thanks.
Martin
Keep in mind that future versions of the TestKit will run in an isolated environment disconnected from the “user space”. In turn configuration (gradle.properties, init scripts etc.) in the default Gradle user home directory (usually <user.home>/.gradle) won’t be picked up anymore.
Generally it’s considered bad practice to rely on user configuration as part of the test assumptions. Instead create relevant configuration in your test setup.