# Unit test for a function in custom gradle plugin

**URL:** <https://discuss.gradle.org/t/unit-test-for-a-function-in-custom-gradle-plugin/25332>\
**Category:** Help/Discuss\
**Created:** [January 4, 2018, 6:23am UTC](https://discuss.gradle.org/t/unit-test-for-a-function-in-custom-gradle-plugin/25332 "2018-01-04T06:23:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nishchay-p](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@Nishchay-p](https://discuss.gradle.org/u/Nishchay-p)\
**Post date:** [January 4, 2018, 6:23am UTC](https://discuss.gradle.org/t/unit-test-for-a-function-in-custom-gradle-plugin/25332/1 "2018-01-04T06:23:52Z")

</div>

Hi,

I created a gradle plugin using groovy.The plugin has a class that in turn has a function to modify and copy a json file from one location to another.

def copyFunction {  
project.copy {  
from 'source location’  
into 'target location’  
filter ( ReplaceTokens, tokens: [‘key’: ‘value’])  
}  
}

How can i write a unit test case for this function?  
Please help as i am pretty new to gradle .

Thanks in advance

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [January 5, 2018, 5:51am UTC](https://discuss.gradle.org/t/unit-test-for-a-function-in-custom-gradle-plugin/25332/2 "2018-01-05T05:51:24Z")

</div>

There is a Gradle Guide on [Testing Gradle plugins](https://guides.gradle.org/testing-gradle-plugins/).

However, you haven’t written any custom logic that’s unit testable or really even integration testable. You’re calling the Gradle API to copy actual files in the context of a build, so you should focus on the functional testing section of the guide and documentation on using [Gradle TestKit](https://docs.gradle.org/current/userguide/test_kit.html).

---

<div class="post-metadata">

**Author:** ![Nishchay-p](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@Nishchay-p](https://discuss.gradle.org/u/Nishchay-p)\
**Post date:** [January 8, 2018, 6:48am UTC](https://discuss.gradle.org/t/unit-test-for-a-function-in-custom-gradle-plugin/25332/3 "2018-01-08T06:48:42Z")

</div>

Thanks james . I got the point.
