# Determining if a compile task and/or source set is for test

**URL:** <https://discuss.gradle.org/t/determining-if-a-compile-task-and-or-source-set-is-for-test/33263>\
**Category:** Help/Discuss\
**Created:** [September 22, 2019, 1:39pm UTC](https://discuss.gradle.org/t/determining-if-a-compile-task-and-or-source-set-is-for-test/33263 "2019-09-22T13:39:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgoldberg](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@rgoldberg](https://discuss.gradle.org/u/rgoldberg)\
**Post date:** [September 22, 2019, 1:39pm UTC](https://discuss.gradle.org/t/determining-if-a-compile-task-and-or-source-set-is-for-test/33263/1 "2019-09-22T13:39:39Z")

</div>

What is the best way to determine if a compile task is for test code?

The best potential solution I’ve thought of so far is:

```gradle
val compileMyTestJava by tasks.getting
val testClasses by tasks.getting

testClasses.taskDependencies.getDependencies(testClasses).contains(compileMyTestJava)

```

Also, is there any way to determine if a `SourceSet` is for test code?

Should I associate the `SourceSet` with a `Task` via naming conventions, and then use the `Task` test heuristic?

Or should I associate them via `SourceSet` directories & `Task#inputs`?

I’ve seen `SourceSet#output#outputDirectories#builtBy`, but the `outputDirectories` field doesn’t seem to be easily accessible.
