The*_*eth 6 testing android robolectric robolectric-gradle-plugin
我正在努力让Robolectric测试并在我们当前的项目中工作,而且没有太多运气.我的偏好是让它们在Android Studio 1.1.0+中运行.这是我的项目结构:

这是我的测试:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
无论我做什么来尝试通过更改清单的路径来让框架找到测试,它都找不到它 - 我得到WARNING: No manifest file found at ./AndroidManifest.xml.Falling back to the Android OS resources only.消息或API Level XX is not supported - Sorry!消息.最后,我认为这是我在测试运行时遇到以下错误的原因:
android.content.res.Resources$NotFoundException: unknown resource 2130903074
Run Code Online (Sandbox Code Playgroud)
我确实打开了实验选项,配置了正确的Gradle插件(单元测试工作正常),但我不确定我缺少什么来启动和运行测试测试.
应用级构建文件:
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'
Run Code Online (Sandbox Code Playgroud)
顶级构建文件:
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'org.robolectric:robolectric-gradle-plugin:1.0.0'
}
Run Code Online (Sandbox Code Playgroud)
nen*_*ick 10
我写了一步一步指导如何使用android studio 1.1.0启用robolectric http://nenick-android.blogspot.de/2015/02/android-studio-110-beta-4-and.html我猜你会的找到你的问题的答案.还有一个例子https://github.com/nenick/AndroidStudioAndRobolectric