There is no single purpose tool for this. OTOH there are various possibilities how to test your code. If your build logic is in buildSrc
project - http://www.gradle.org/docs/current/userguide/organizing_build_logic.html#sec:build_sources - you can put your testing code there. Of course you have to decide how to test your code to avoid interaction like repository changes.
You can take a look at Gradle codebase. There are plenty of integration tests where you can find ideas. Aside from unittest it is likely you will want to use Gradle Tooling API to control build started from your tests.