Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use gradle-android-test-plugin
    primarykey
    data
    text
    <p>I want to get Robolectric working with Android Studio and am attempting to use [gradle-android-test-plugin][1] after reviewing answers to this [question][2], but am having no luck.</p> <ol> <li>I created a brand new Android project and named it MyApp.</li> <li>I followed all the instructions in the "Usage" section of the README.</li> <li>I didn't yet have any code to test in my new project, so I copied the classes (including the `RobolectricGradleTestRunner`) from the</li> </ol> <pre><code>gradle-android-test-plugin/example/src/test/java/com/example </code></pre> <p>and the</p> <pre><code>gradle-android-test-plugin/example/src/main/java/com/example </code></pre> <p>directories into corresponding file paths in my new MyApp project.</p> <p>I've never implemented unit testing for Android before and I don't know what to do next. I successfully ran <strong><code>./gradlew install</code></strong> in the root directory of the the plugin, but doing the same in the root directory of my new project accomplishes nothing. It throws this complaint:</p> <pre><code>Task 'install' is ambiguous in root project 'MyApp'. Candidates are: 'installDebug', 'installTest'. </code></pre> <p>I'm not at all familiar with Gradle, so short of reading a textbook on Gradle itself, I'm not sure how to resolve this issue. </p> <p>If I enter the MyApp directory containing <code>AndroidManifest.xml</code> and try the <strong><code>../gradlew clean check</code></strong> to build and run the tests, I get this error:</p> <pre><code>Could not determine the dependencies of task ':MyApp:testDebug'. </code></pre> <p>Android Studio doesn't seem to be having any issues finding my dependencies. Can someone point me in the direction of running my tests, please? I imagine it's a simple terminal command or something that wasn't mentioned in the plugin's README. Cheers!</p> <p>edit:</p> <p>Here is my <code>build.gradle</code>. I'm aware it's not structurally identical to that of the example project included with the plugin, but that structure gave me identical errors.</p> <pre><code>buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.+' } } apply plugin: 'android' apply plugin: 'android-test' repositories { mavenCentral() } android { compileSdkVersion 18 buildToolsVersion "18.0.1" defaultConfig { minSdkVersion 11 targetSdkVersion 18 } } dependencies { compile 'com.android.support:support-v4:18.0.0' testCompile 'junit:junit:4.11' testCompile 'org.robolectric:robolectric:2.1.+' testCompile 'com.squareup:fest-android:1.0.+' } </code></pre> <p>edit2: Besides the fact that I was issuing the wrong commands (as indicated in Ravindra's answer), I also failed to realize my version of Gradle was too new (as Jake's comment points out).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload