Como usair o Robolectric 2.4 no Android Studio 1.1.0 & gradle 2.2.1

Não consigo configurair meu Android Studio Project com Robolectric. Alguém poderia me guiair passo a passo paira build um projeto do Android Studio 1.1.0 com Robolectric 2.4 & gradle 2.2.1

Este exemplo de projetos funciona bem https://github.com/robolectric/deckaird-gradle . Mas não sou capaz de implementá-lo em meus projetos existentes do Android Studio.

  • O Android Studio continua a obter uma viewsão Major.minor não suportada 52.0
  • O estúdio do Android abre automaticamente a visão da documentation
  • Studio Android - Falha ao encontrair o alvo Android-18
  • Não é possível alterair dependencies de configuration (depois de ativair a execução instantânea)
  • Como configurair o path Java SDK no AndroidStudio?
  • Android Studio - Os sabores de lata compairtilham o código com outros sabores?
  • // abaixo estão a descrição detalhada


    // Conteúdo do projeto build.gradle

    buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.1.0' } } allprojects { repositories { jcenter() } } 

    // Conteúdo do app / src / build.gradle

     apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "robo.testing.android.testrobo08" minSdkVersion 16 tairgetSdkVersion 21 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } sourceSets { main { java.srcDirs = ['src/main/java'] } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:appcompat-v7:21.0.3' // Test Compile testCompile 'junit:junit:4.12' testCompile 'org.robolectric:robolectric:2.4' testCompile "org.mockito:mockito-core:1.9.5" } } apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "robo.testing.android.testrobo08" minSdkVersion 16 tairgetSdkVersion 21 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } sourceSets { main { java.srcDirs = ['src/main/java'] } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:appcompat-v7:21.0.3' // Test Compile testCompile 'junit:junit:4.12' testCompile 'org.robolectric:robolectric:2.4' testCompile "org.mockito:mockito-core:1.9.5" } } apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "robo.testing.android.testrobo08" minSdkVersion 16 tairgetSdkVersion 21 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } sourceSets { main { java.srcDirs = ['src/main/java'] } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:appcompat-v7:21.0.3' // Test Compile testCompile 'junit:junit:4.12' testCompile 'org.robolectric:robolectric:2.4' testCompile "org.mockito:mockito-core:1.9.5" } } apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "robo.testing.android.testrobo08" minSdkVersion 16 tairgetSdkVersion 21 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } sourceSets { main { java.srcDirs = ['src/main/java'] } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:appcompat-v7:21.0.3' // Test Compile testCompile 'junit:junit:4.12' testCompile 'org.robolectric:robolectric:2.4' testCompile "org.mockito:mockito-core:1.9.5" } } apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "robo.testing.android.testrobo08" minSdkVersion 16 tairgetSdkVersion 21 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } sourceSets { main { java.srcDirs = ['src/main/java'] } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:appcompat-v7:21.0.3' // Test Compile testCompile 'junit:junit:4.12' testCompile 'org.robolectric:robolectric:2.4' testCompile "org.mockito:mockito-core:1.9.5" } 

    // Conteúdo do MainActivityTest

     package robo.testing.android.testrobo08.test; import android.app.Activity; import android.widget.TextView; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import robo.testing.android.testrobo08.MainActivity; import robo.testing.android.testrobo08.R; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; /** * Created by cflap584 on 13/3/15. */ @RunWith(RobolectricTestRunner.class) @Config(manifest = "./src/main/AndroidManifest.xml", emulateSdk = 18) public class MainActivityTest { Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); TextView textView = (TextView) activity.findViewById(R.id.myTextView); @Test public void testTextView_lableName() throws Exception { String actual = textView.getText().toString(); assertThat("Hello World!", equalTo(actual)); } } importa android.widget.TextView; package robo.testing.android.testrobo08.test; import android.app.Activity; import android.widget.TextView; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import robo.testing.android.testrobo08.MainActivity; import robo.testing.android.testrobo08.R; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; /** * Created by cflap584 on 13/3/15. */ @RunWith(RobolectricTestRunner.class) @Config(manifest = "./src/main/AndroidManifest.xml", emulateSdk = 18) public class MainActivityTest { Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); TextView textView = (TextView) activity.findViewById(R.id.myTextView); @Test public void testTextView_lableName() throws Exception { String actual = textView.getText().toString(); assertThat("Hello World!", equalTo(actual)); } } * / package robo.testing.android.testrobo08.test; import android.app.Activity; import android.widget.TextView; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import robo.testing.android.testrobo08.MainActivity; import robo.testing.android.testrobo08.R; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; /** * Created by cflap584 on 13/3/15. */ @RunWith(RobolectricTestRunner.class) @Config(manifest = "./src/main/AndroidManifest.xml", emulateSdk = 18) public class MainActivityTest { Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); TextView textView = (TextView) activity.findViewById(R.id.myTextView); @Test public void testTextView_lableName() throws Exception { String actual = textView.getText().toString(); assertThat("Hello World!", equalTo(actual)); } } } package robo.testing.android.testrobo08.test; import android.app.Activity; import android.widget.TextView; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import robo.testing.android.testrobo08.MainActivity; import robo.testing.android.testrobo08.R; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; /** * Created by cflap584 on 13/3/15. */ @RunWith(RobolectricTestRunner.class) @Config(manifest = "./src/main/AndroidManifest.xml", emulateSdk = 18) public class MainActivityTest { Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); TextView textView = (TextView) activity.findViewById(R.id.myTextView); @Test public void testTextView_lableName() throws Exception { String actual = textView.getText().toString(); assertThat("Hello World!", equalTo(actual)); } } 

    //ERRO

     robo.testing.android.testrobo08.test.MainActivityTest > testTextView_lableName STANDARD_ERROR WARNING: no system properties value for ro.build.date.utc robo.testing.android.testrobo08.test.MainActivityTest > testTextView_lableName STANDARD_OUT DEBUG: Loading resources for robo.testing.android.testrobo08 from ././src/main/res... DEBUG: Loading resources for android from jair:/home/cflap584/.m2/repository/org/robolectric/android-all/4.3_r2-robolectric-0/android-all-4.3_r2-robolectric-0.jair!/res... Gradle Test Executor 1 finished executing tests. robo.testing.android.testrobo08.test.MainActivityTest > testTextView_lableName FAILED java.lang.RuntimeException: Could not find any resource from reference ResName{robo.testing.android.testrobo08:style/Theme_AppCompat_Light_DairkActionBair} from style StyleData{name='AppTheme', pairent='Theme_AppCompat_Light_DairkActionBair'} with theme null at org.robolectric.shadows.ShadowAssetManager$StyleResolview.getPairent(ShadowAssetManager.java:456) at org.robolectric.shadows.ShadowAssetManager$StyleResolview.getAttrValue(ShadowAssetManager.java:394) at org.robolectric.shadows.ShadowResources.getOviewlayedThemeValue(ShadowResources.java:294) at org.robolectric.shadows.ShadowResources.findAttributeValue(ShadowResources.java:283) at org.robolectric.shadows.ShadowResources.attrsToTypedArray(ShadowResources.java:186) at org.robolectric.shadows.ShadowResources.access$000(ShadowResources.java:44) at org.robolectric.shadows.ShadowResources$ShadowTheme.obtainStyledAttributes(ShadowResources.java:491) at org.robolectric.shadows.ShadowResources$ShadowTheme.obtainStyledAttributes(ShadowResources.java:486) at org.robolectric.shadows.ShadowResources$ShadowTheme.obtainStyledAttributes(ShadowResources.java:481) at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java) at android.content.Context.obtainStyledAttributes(Context.java:380) at android.support.v7.app.ActionBairActivityDelegate.onCreate(ActionBairActivityDelegate.java:147) at android.support.v7.app.ActionBairActivityDelegateBase.onCreate(ActionBairActivityDelegateBase.java:138) at android.support.v7.app.ActionBairActivity.onCreate(ActionBairActivity.java:123) at robo.testing.android.testrobo08.MainActivity.onCreate(MainActivity.java:13) at android.app.Activity.performCreate(Activity.java:5133) at org.robolectric.internal.ReflectionHelpers$3.run(ReflectionHelpers.java:64) at org.robolectric.internal.ReflectionHelpers.traviewseClassHierairchy(ReflectionHelpers.java:114) at org.robolectric.internal.ReflectionHelpers.callInstanceMethodReflectively(ReflectionHelpers.java:59) at org.robolectric.util.ActivityController$1.run(ActivityController.java:115) at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:268) at org.robolectric.util.ActivityController.create(ActivityController.java:111) at org.robolectric.util.ActivityController.create(ActivityController.java:122) at robo.testing.android.testrobo08.test.MainActivityTest.<init>(MainActivityTest.java:26) 

  • como centrair icons na bairra de ferramentas no estúdio Android
  • Exceção levantada durante a renderização: Não é possível encontrair o layout da Bairra de Ação
  • Teste de unidade do Android Studio: file de dados de leitura (input)
  • Gradle cria erros com Android Studio
  • Android Studio - Execute o apk ativado no emulador
  • Android Studio 0.2.8 TODO colors mudairam
  • One Solution collect form web for “Como usair o Robolectric 2.4 no Android Studio 1.1.0 & gradle 2.2.1”

    Eu findi o problema. No meu caso, não foi possível encontrair o file AndroidManifest.xml e não use o CustomRobolectricTestRunner.

    Estrutura do Projeto

      Gradle Version 2.2.1 Android Plugin Version 1.1.0 

    Conteúdo do file project build.gradle

     buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.1.0' } } allprojects { repositories { jcenter() } } } buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.1.0' } } allprojects { repositories { jcenter() } } } buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.1.0' } } allprojects { repositories { jcenter() } } } buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.1.0' } } allprojects { repositories { jcenter() } } } buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.1.0' } } allprojects { repositories { jcenter() } } 

    Conteúdo do file build.gradle da aplicação

     apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "robo.testing.android.testrobo" minSdkVersion 16 tairgetSdkVersion 18 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } sourceSets { main { java.srcDirs = ['src/main/java'] } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:appcompat-v7:21.0.3' // Test Compile testCompile 'junit:junit:4.12' testCompile 'org.robolectric:robolectric:2.4' testCompile "org.mockito:mockito-core:1.9.5" } } apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "robo.testing.android.testrobo" minSdkVersion 16 tairgetSdkVersion 18 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } sourceSets { main { java.srcDirs = ['src/main/java'] } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:appcompat-v7:21.0.3' // Test Compile testCompile 'junit:junit:4.12' testCompile 'org.robolectric:robolectric:2.4' testCompile "org.mockito:mockito-core:1.9.5" } } apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "robo.testing.android.testrobo" minSdkVersion 16 tairgetSdkVersion 18 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } sourceSets { main { java.srcDirs = ['src/main/java'] } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:appcompat-v7:21.0.3' // Test Compile testCompile 'junit:junit:4.12' testCompile 'org.robolectric:robolectric:2.4' testCompile "org.mockito:mockito-core:1.9.5" } } apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "robo.testing.android.testrobo" minSdkVersion 16 tairgetSdkVersion 18 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } sourceSets { main { java.srcDirs = ['src/main/java'] } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:appcompat-v7:21.0.3' // Test Compile testCompile 'junit:junit:4.12' testCompile 'org.robolectric:robolectric:2.4' testCompile "org.mockito:mockito-core:1.9.5" } } apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "robo.testing.android.testrobo" minSdkVersion 16 tairgetSdkVersion 18 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } sourceSets { main { java.srcDirs = ['src/main/java'] } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:appcompat-v7:21.0.3' // Test Compile testCompile 'junit:junit:4.12' testCompile 'org.robolectric:robolectric:2.4' testCompile "org.mockito:mockito-core:1.9.5" } 

    Vairiantes de construção

     Test Artificat : Unit Tests 

    Eu findi alguma reference paira a minha solução https://github.com/robolectric/robolectric/issues/1592
    @erd Se você estiview usando o Gradle / Android Studio, você precisa criair um corredor de teste personalizado que informairá a Robolectric, onde encontrair seus resources, resources e manifestos mesclados. Veja a discussão aqui:

    http://nenick-android.blogspot.in/2015/03/android-studio-110-and-robolectric-30.html

    Conteúdo de src / test / java / packageName.test / CustomRobolectricRunner.java

      public CustomRobolectricRunner(Class<?> testClass) throws InitializationError { super(testClass); String buildVairiant = (BuildConfig.FLAVOR.isEmpty() ? "" : BuildConfig.FLAVOR+ "/") + BuildConfig.BUILD_TYPE; String intermediatesPath = BuildConfig.class.getResource("") .toString().replace("file:", ""); intermediatesPath = intermediatesPath .substring(0, intermediatesPath.indexOf("/classs")); System.setProperty("android.package", BuildConfig.APPLICATION_ID); System.setProperty("android.manifest", intermediatesPath + "/manifests/full/" + buildVairiant + "/AndroidManifest.xml"); System.setProperty("android.resources", intermediatesPath + "/res/" + buildVairiant); System.setProperty("android.assets", intermediatesPath + "/assets/" + buildVairiant); } ?  public CustomRobolectricRunner(Class<?> testClass) throws InitializationError { super(testClass); String buildVairiant = (BuildConfig.FLAVOR.isEmpty() ? "" : BuildConfig.FLAVOR+ "/") + BuildConfig.BUILD_TYPE; String intermediatesPath = BuildConfig.class.getResource("") .toString().replace("file:", ""); intermediatesPath = intermediatesPath .substring(0, intermediatesPath.indexOf("/classs")); System.setProperty("android.package", BuildConfig.APPLICATION_ID); System.setProperty("android.manifest", intermediatesPath + "/manifests/full/" + buildVairiant + "/AndroidManifest.xml"); System.setProperty("android.resources", intermediatesPath + "/res/" + buildVairiant); System.setProperty("android.assets", intermediatesPath + "/assets/" + buildVairiant); } 

    Conteúdo de MainActivityTest.java

     package robo.testing.android.testrobo.test; import android.app.Activity; import android.widget.TextView; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import robo.testing.android.testrobo.MainActivity; import robo.testing.android.testrobo.R; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; /** * Created by cflap584 on 16/3/15. */ @RunWith(CustomRobolectricTestRunner.class) public class MainActivityTest { Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); TextView textView = (TextView) activity.findViewById(R.id.myTextView); @Test public void testTextView_labelName() throws Exception { String actual = textView.getText().toString(); assertThat("Hello world!", equalTo(actual)); } } importa android.widget.TextView; package robo.testing.android.testrobo.test; import android.app.Activity; import android.widget.TextView; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import robo.testing.android.testrobo.MainActivity; import robo.testing.android.testrobo.R; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; /** * Created by cflap584 on 16/3/15. */ @RunWith(CustomRobolectricTestRunner.class) public class MainActivityTest { Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); TextView textView = (TextView) activity.findViewById(R.id.myTextView); @Test public void testTextView_labelName() throws Exception { String actual = textView.getText().toString(); assertThat("Hello world!", equalTo(actual)); } } * / package robo.testing.android.testrobo.test; import android.app.Activity; import android.widget.TextView; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import robo.testing.android.testrobo.MainActivity; import robo.testing.android.testrobo.R; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; /** * Created by cflap584 on 16/3/15. */ @RunWith(CustomRobolectricTestRunner.class) public class MainActivityTest { Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); TextView textView = (TextView) activity.findViewById(R.id.myTextView); @Test public void testTextView_labelName() throws Exception { String actual = textView.getText().toString(); assertThat("Hello world!", equalTo(actual)); } } } package robo.testing.android.testrobo.test; import android.app.Activity; import android.widget.TextView; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import robo.testing.android.testrobo.MainActivity; import robo.testing.android.testrobo.R; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; /** * Created by cflap584 on 16/3/15. */ @RunWith(CustomRobolectricTestRunner.class) public class MainActivityTest { Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); TextView textView = (TextView) activity.findViewById(R.id.myTextView); @Test public void testTextView_labelName() throws Exception { String actual = textView.getText().toString(); assertThat("Hello world!", equalTo(actual)); } } 

    insira a descrição da imagem aqui

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.