Loading properties when testing a plugin with ProjectBuilder

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

I just found that this is solved since Gradle 2.6-rc-1 by using the testCompile gradleTestKit().

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.

Good point. Will do right now. Thanks!

Ok, hidding the user ~/.gradle/gradle.properties can be done:

import org.junit.Rule
import org.junit.rules.TemporaryFolder
...
@Rule final TemporaryFolder testUserHome = new TemporaryFolder()
...
testUserHome.newFile('empty.txt')
...
def result = GradleRunner
  .create()
  .withArguments(
    '--project-prop','a.b.c=123',
    '--gradle-user-home', testUserHome.getRoot().getName()
  )