Hi! I’m writing a set of plugins for gradle. I’m testing the plugins and other pieces od code with spock framework. I don’t want to test my plugins on real projects because it’s too time-consuming - these will be functional tests run from to time to time. For everyday testing i need a set of quick unit tests. So the question is: do You know any good mocking technique for org.gradle.api.Project class and other gradle classes? How to You test gradle plugins?
For “unit” tests you can use ‘org.gradle.testfixtures.ProjectHelper’. For functional tests you can use the tooling API. We plan to provide more testing support in the future.
You meant ‘org.gradle.textfixtures.ProjectBuilder’? I’m already using this class as well as gradle tooling API. The problem is that it seems to work quite slow in some cases. Nevertheless thanks for the hint and waiting for testing support. What does ‘future’ mean in this case?
Yeah, it’s ‘org.gradle.testfixtures.ProjectBuilder’. When you are using this class, you aren’t truly writing unit tests, and it takes some time to set up the fake project(s). I can’t say when enhanced testing support will become available.
Ok, so with ‘org.gradle.api.ProjectBuilder’ it rather move towards integration testing. Thanks for the clarification.
are there examples [of using the tooling api like this] in the gradle src code?
Yes, investigate ‘$GRADLE_HOME/samples/toolingApi/’ and ‘$GRADLE_HOME/customPlugin’
Not sure, as Gradle has its own internal functional testing infrastructure. The samples in the full Gradle distribution include samples for the tooling API.