How to test cacheable Tasks?

(Devi Sridharan) #1

Hi Gradle Team,

We recently started using build-cache in our company. We have updated many gradle tasks/plugins to be cache-friendly. Build cache has improved build speed to greater extent.

As next step, I’m looking for ways to add tests for gradle tasks to verify cacheability. We added few tests using gradle test-kit library. But, it takes lot of time as we are setting up new projects using TemporaryFolder to verify scenarios listed in gradle docs. I need to explicitly setup project dependencies, build files and release the plugins locally before test starts. Also, tests downloads this dependencies for every test run.

I’m looking for recommendations on adding tests for cacheable tasks.

  • What are recommended usecases that i should test for cacheable tasks?(other than these )
  • Is there gradle doc available on how to add tests for cacheable tasks?
  • Can i test cacheability of tasks in unit-test fashion(i.e without setting up project, build.gradle, dependencies, local version of plug-ins)?

(Eric Wendelin) #2

I suggest you start with this doc and let us know if that doc doesn’t answer all your questions.

(Devi Sridharan) #3

Thank you for the link Eric.

What are recommended testcases(I’m interested in knowing negative testcases) for cacheable tasks?

(Stefan Wolf) #4

You should probably test the following:

  • running the task, clean, re-run the task - the task should be cached
  • running the task in one directory and re-create the project in a different location and running the same task there. The task should be cached. This is a test for relocatability.
  • change the different inputs of the task and make sure the task is out of date afterwards