Skip to content

Instantly share code, notes, and snippets.

@s1rius
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s1rius/8909322 to your computer and use it in GitHub Desktop.
Save s1rius/8909322 to your computer and use it in GitHub Desktop.
RobolectricGraldeTestRunner build.gradle
buildscript {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
}
}
apply plugin: 'android'
apply plugin: 'android-test'
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile "com.android.support:appcompat-v7:18.0.+"
compile project(":libraries:Slidinglibrary")
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.1.+'
testCompile 'com.squareup:fest-android:1.0.+'
instrumentTestCompile 'junit:junit:4.10'
instrumentTestCompile 'org.robolectric:robolectric:2.1.+'
instrumentTestCompile 'com.squareup:fest-android:1.0.+'
}
android {
compileSdkVersion 19
buildToolsVersion "19"
sourceSets {
instrumentTest.setRoot('src/test')
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
}
package com.mypackage;
import static org.junit.Assert.assertEquals;
import org.junit.runner.RunWith;
import org.junit.Test;
import org.robolectric.RobolectricTestRunner;
import android.app.Activity;
import android.widget.TextView;
@RunWith(RobolectricTestRunner.class)
public class FirstTest {
@Test
public void testInstantiation() {
MainActivity mainActivity = new MainActivity();
TextView tv = new TextView(activity);
tv.setText("e84");
assertEquals("e84", tv.getText());
throw new RuntimeException("Robolectric is awesome!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment