清单和设置问题得到Robolectric采用Android 1.1.0工作室工作 [英] Manifest and setup issues getting Robolectric working with Android Studio 1.1.0

查看:393
本文介绍了清单和设置问题得到Robolectric采用Android 1.1.0工作室工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得Robolectric测试和在我们目前的项目中工作,而不是有很多运气。我的preference将让这些到Android Studio中运行1.1.0+。这是我的项目结构:

这里是我的测试:

 进口android.widget.Button;进口com.mycompany.android.app.R;进口org.junit.Before;
进口org.junit.Test;
进口org.junit.runner.RunWith;
进口org.robolectric.Robolectric;
进口org.robolectric.RobolectricTestRunner;
进口org.robolectric.annotation.Config;引入静态org.junit.Assert.assertNotNull;@Config(舱单=AndroidManifest.xml中)
@RunWith(RobolectricTestRunner.class)
公共类SplashActivityTest {    私人SplashActivity splashActivity;    @之前
    公共无效设置(){
        splashActivity = Robolectric.buildActivity(SplashActivity.class).create()开始()恢复()获得()。;
    }    @测试
    公共无效shouldNotBeNull(){
        按钮signUpButton =(按钮)sp​​lashActivity.findViewById(R.id.sign_up_button);
        assertNotNull(signUpButton);        按钮loginButton =(按钮)sp​​lashActivity.findViewById(R.id.login_button);
        assertNotNull(loginButton);
    }}

不管我做什么,试图让该框架发现通过改变清单中的道路测试,它无法找到它 - 或者我得到警告:在./AndroidManifest没有发现清单文件。.xml.Falling回到了Android操作系统的资源只有消息或 API级别XX不支持 - 对不起!消息。最后,我想这是我收到以下错误,当测试运行的原因:

  android.content.res.Resources $ NotFoundException:未知的资源2130903074

我有实验选项打开,有正确的摇篮插件配置(单位的测试工作正常),但我不知道我的思念让仪器测试启动和运行

应用程序级别的生成文件:

 应用插件:'org.robolectrictestCompile'的JUnit:JUnit的:4.12
testCompile'org.mockito:的Mockito核心:1.9.5
testCompile'org.robolectric:robolectric:2.4
testCompile'org.hamcrest:hamcrest核心:1.1
testCompile'org.hamcrest:hamcrest库:1.1
testCompile'org.hamcrest:hamcrest集成:1.1

顶级构建文件:

  {相关性
    类路径'com.android.tools.build:gradle:1.1.0
    类路径'org.robolectric:robolectric-gradle这个-插件:1.0.0
}


解决方案

我写了一个一步一步的指导如何启用与Android 1.1.0工作室<一robolectric href=\"http://nenick-android.blogspot.de/2015/02/android-studio-110-beta-4-and.html\">http://nenick-android.blogspot.de/2015/02/android-studio-110-beta-4-and.html我猜你会发现你的问题的答案。并举例<一个href=\"https://github.com/nenick/AndroidStudioAndRobolectric\">https://github.com/nenick/AndroidStudioAndRobolectric

I am trying to get Robolectric tests up and working in our current project, and not having a lot of luck. My preference would be to get these to run within Android Studio 1.1.0+. This is my project structure:

and here is my test:

import android.widget.Button;

import com.mycompany.android.app.R;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import static org.junit.Assert.assertNotNull;

@Config(manifest = "AndroidManifest.xml")
@RunWith(RobolectricTestRunner.class)
public class SplashActivityTest {

    private SplashActivity splashActivity;

    @Before
    public void setup() {
        splashActivity = Robolectric.buildActivity(SplashActivity.class).create().start().resume().get();
    }

    @Test
    public void shouldNotBeNull() {
        Button signUpButton = (Button) splashActivity.findViewById(R.id.sign_up_button);
        assertNotNull(signUpButton);

        Button loginButton = (Button) splashActivity.findViewById(R.id.login_button);
        assertNotNull(loginButton);
    }

}

No matter what I do to try and get the framework to find the test by changing the path to the manifest, it cannot find it - either I get WARNING: No manifest file found at ./AndroidManifest.xml.Falling back to the Android OS resources only. messages, or API Level XX is not supported - Sorry! messages. In the end, I think this is the reason I'm getting the following errors when the test runs:

android.content.res.Resources$NotFoundException: unknown resource 2130903074

I do have the experimental option turned on, have the right Gradle plugin configured (unit tests work fine), but I'm not sure what I'm missing to get instrumentation tests up and running.

App-level build file:

apply plugin: 'org.robolectric'

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'org.hamcrest:hamcrest-core:1.1'
testCompile 'org.hamcrest:hamcrest-library:1.1'
testCompile 'org.hamcrest:hamcrest-integration:1.1'

Top-level build file:

dependencies {
    classpath 'com.android.tools.build:gradle:1.1.0'
    classpath 'org.robolectric:robolectric-gradle-plugin:1.0.0'
}

解决方案

I wrote a step by step guide how to enable robolectric with android studio 1.1.0 http://nenick-android.blogspot.de/2015/02/android-studio-110-beta-4-and.html I guess you will find an answer for your issue. And an example https://github.com/nenick/AndroidStudioAndRobolectric

这篇关于清单和设置问题得到Robolectric采用Android 1.1.0工作室工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆