I would like to create a gradle method that would return me a boolean saying if a project passed as input has some tests defined in a particular sub folder. Particularly, I am interested in knowing if the project contains android instrumentation tests.
So far, this is what I have (my root project has multiple sub-projects):
def doesProjectContainsInstrumentationTests(project) {
def rootDir = new File(rootProject.rootDir, "")
def projectPath = project.getPath().replaceAll(':', '/')
def fullPath = new File(rootDir, projectPath)
def androidTestFolder = new File(fullPath, "src/androidTest")
//TODO: find a better way to detect if the module has instrumentation tests to run (using some annotation like @Test or @RunWith?)
def containsInstrumentationTests = androidTestFolder.exists()
return containsInstrumentationTests
}
The problem with this implementation is that the folder might exist but no tests are in it. In that situation, the code above would return true while it should return false.
Ideally I would like to reuse the same logic described here, but not sure I can do it.
Any suggestion on how I could achieve that? I'm ok if there is a completly different way to achieve that, as long as it works :)