Running Android unit tests with Spock framework
<p>I am using:</p>

<ul>
<li>Android Studio 2.1.3</li>
<li>Gradle 2.14.1 (I tried with 2.14 also)</li>
<li>OpenJDK version "1.8.0_91"</li>
</ul>

<p>I want to write some Unit tests with <a href="http://groovy-lang.org" rel="nofollow noreferrer">Groovy</a> and <a href="http://spockframework.github.io/spock/docs/1.1-rc-2/index.html" rel="nofollow noreferrer">Spock</a> for sample Android application.</p>

<p>I have already read about <a href="http://robospock.org/" rel="nofollow noreferrer">RoboSpock</a>.</p>

<p>When I am trying to run simple test:</p>

<pre><code>package a.b.regex

class TestSum extends spock.lang.Specification {

    def "test adding some numbers"() {
        when:
        def a = 5 + 4

        then:
        a == 9
    }
}
</code></pre>

<p>When I try to run this test in Android Studio I have an error:</p>

<pre><code>Process finished with exit code 1
Class not found: "a.b.regex.TestSum"Empty test suite.
</code></pre>

<p>Configurations that I used:</p>

<p>1)</p>

<pre><code>buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
        classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.6'
    }
}

apply plugin: 'groovyx.grooid.groovy-android'
// ...
dependencies {
    testCompile 'org.robospock:robospock:1.0.0'
}
</code></pre>

<p>2)</p>

<pre><code>buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
        classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:1.0.0'
    }
}

apply plugin: 'groovyx.android'
dependencies {
    testCompile "org.codehaus.groovy:groovy-all:2.4.1"
    testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
    testCompile 'org.codehaus.groovy:groovy:2.4.6:grooid'
}
</code></pre>

<p>From the console no tests are run at all.
With testing Java applications I have no problem.</p>

<p>Here is the project code where I want to use Spock: <a href="https://github.com/Abrasha/Streets-Translator" rel="nofollow noreferrer">GitHub repository</a></p>

<p><strong>Thankfully to <a href="https://stackoverflow.com/a/39214788/5091346">Pieces</a> I found the answer.</strong></p>

<p>You should use the following configuration:</p>

<pre><code>apply plugin: 'groovyx.android'

buildscript {
    repositories {
        jcenter() // or mavenCentral, etc.
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
        classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:1.0.0'
    }
}

testCompile 'org.codehaus.groovy:groovy:2.4.7:grooid'
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
    exclude group: 'org.codehaus.groovy'
    exclude group: 'junit'
}
</code></pre>