I was experimenting with spock last week and happened upon the RoboSpock plugin while trying to figure out how to combine Robolectric and Spock. The plugin made it easier for me to get going with spock on my Android project. Thanks!
I'm only just getting started with spock, but I like the way in which it enables expressive, concise tests. IMHO this is very desirable property in a test suite, especially if you use it to highlight the domain behavior that is being tested.
This is an example of the kind of choice I had in mind when I suggested that it would be very desirable for the Android plugin to expose an API that makes it straightforward to express the dependency of unit test code on the Android SDK, the compiled classes from the Android app/lib, and the directory that contains the AndroidManifest.xml. This approach gives developers the freedom to choose a testing framework/library that is most appropriate for their needs.
As it stands with version 0.3.1 of RoboSpock, it resolves the SDK dependency with com.google.android:android:4.1.1.4. This may be fine for some projects, but will it work properly if the code under test or the unit tests have dependencies on features introduced more recently that 4.1?
The particular unit test I started with also highlighted another issue that occurs when app or test code uses libraries bundled with the Android SDK. My particular case makes use of org.json.JSONObject. The stubbed version of this class is present in android.jar. In order to actually execute my tests and avoid the "stub" exception, it was necessary to exclude the transitive dependency on com.google.android:android, add an explicit dependency on org.json:json:20080701, and adjust the classpath so that at test runtime the non-stubbed version was loaded instead of the stubs bundled in android.jar. I imaging a similar situation applies for the other XML and other APIs that are bundled with android.jar.
It seems that core gradle does not provide a way to control the order of dependencies other than by manipulating the classpath property. Until this is changed, then it is desirable for the Android gradle plugin to expose an API that allows an app to obtain a FileCollection (or File) reference to android.jar that can be appended to classpath.
My work-around in build.gradle uses android.plugin.sdkDirectory to construct the path to android.jar. Based on comments that Xavier made in another thread, I'm guessing that the sdkDirectory property is not part of the public API. I would, of course, prefer that my unit tests only make use of the public API of the Android gradle plugin.
Matthew