Writing unit/integration tests for Gradle plugins


(Kapelonis) #1

Hello

I am the author of the “Java testing with Spock” book that is currently in writing and will be finished at the end of the year. I have comments from readers that they would like to see examples with Spock testing on Gradle plugins.

Now I have already seen posts such as these:




I have also seen this effort

So my question is:
Is there somewhere an authoritative source that explains what is the current situation with testing gradle plugins (and any limitations/tricks that might exist) and what is the roadmap of improving test support for gradle plugins?

Thanks


(Benjamin Muschko) #2

We just started work on the test-kit with 2.6 and will continue to do so in the upcoming versions. You can find the spec for the test-kit in the Gradle repository which roughly outlines the features we are planning to add. Other than that there’s no concrete roadmap. Documentation will be added to the user guide as features are added to the test-kit.

If I’d write a book on Spock testing, I’d not cover the test-kit for various reasons:

  • Explaining what concrete use cases the test-kit is trying to solve requires quite a bit of context around Gradle. I am not sure it would be a good use of your pages count.
  • The test-kit will be testing framework agnostic meaning that there will be nothing specific to Spock.
  • The API will be incubating for a while which means that it might change at any time. This would automatically render your book content incorrect or outdated.
  • I’d see the coverage of the test-kit in a book more closely related to Gradle.

(Kapelonis) #3

Oh wow, very quick response!

Your answer certainly clears up a lot of things for me.

Ok then, I will just point my readers to “Gradle in action” and the official Gradle documentation as it gets enriched along with the test-kit.

Thanks


(Benjamin Muschko) #4

“Gradle in Action” obviously doesn’t cover the test-kit. However, the book covers the underlying mechanics for writing unit, integration and functional tests for build code. If there’s a second edition, it certainly would focus on covering the use cases with the test-kit.


(davidmichaelkarr) #5

Until or whether support for plugin testing is provided directly by the framework, a very good solution in the meantime is the nebula-test plugin. Many of the plugins in the portal already use it.


(Grzegorz Głąb) #6

Hi,

I use https://github.com/nebula-plugins/nebula-test for testing my gradle plugin (it is a standalone gradle plugin, does not use any kind of nebula library).

It can test plugin directly, create gradle build on-the-fly attaching your plugin and check result, or attach to prepared gradle example projects and check result of build on them.

edit:
sorry, I was blind not seeing the post above, but still I can’t find a better alternative.