The issue is that this doesn't support build variants.
It would be interesting to have a helper of sort to create tasks for all variants, but when you start running into setting source folders and dependency configuration that's a bit complicated.
I think it is useful though to allow more than one type of tests, so something specific to that might work.
Something like:
android.createTestTask(baseName, Closure)
would create, for each variant:
- a task called "${baseName}${variantName}" or some other combination of both.
- a dependency configuration object called "${variantName}${baseName}"
- a new source set object called "${baseName}${variantName}" in the android.sourceSets container
Your closure would do the work. We might also want to automatically generate a compile task for it, so that it's separate from the task running the actual test...
There are other things to figure out, like the actual classpath beyond the specific Configuration object (does it extend the app classpath? probably, but there might be options).
After that you're probably on your own to run it, but if you want to run it on the device, you're going to want to have access to whatever we do for the extension and it becomes non simple.
There's a lot of details to figure out.