robolectric

Android build tools 1.1.0, unit test folder?

落花浮王杯 提交于 2019-12-10 03:46:10
问题 I recently installed the latest tools from google to my android project: buildscript { repositories { jcenter() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.1.0' } } allprojects { repositories { jcenter() } } apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } defaultConfig { applicationId "com.xxx"

Robolectric+Eclipse Can't find resources?

心不动则不痛 提交于 2019-12-09 16:33:38
问题 I just configured a test project for my Android app to use Robolectric. I followed the Eclipse Quick Start. An exception is raised executing my simple very first test. java.lang.RuntimeException: java.lang.NullPointerException at com.xtremelabs.robolectric.res.ResourceLoader.init(ResourceLoader.java:93) at com.xtremelabs.robolectric.res.ResourceLoader.getStringValue(ResourceLoader.java:271) at com.xtremelabs.robolectric.shadows.ShadowResources.getString(ShadowResources.java:56) at android

Roboelectric 3.0 testing fragments

不羁的心 提交于 2019-12-08 19:43:50
问题 I am new to Roboelectric testing. I am trying to follow this post to test fragments. I am using following as dependency dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile "org.robolectric:robolectric:3.0" testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:22.2.0' compile 'com.google.code.gson:gson:2.3' compile 'com.android.support:support-v4:22.1.0' compile 'com.google.android.gms:play-services:7.5.0' } But this import is giving me compilation

NoClassDefFoundError while running unit tests with Roboelectric 3.8

老子叫甜甜 提交于 2019-12-08 19:42:12
问题 My Android project has several modules (one application and multiple libraries) and when I try to run all the unit tests ( Robolectric 3.8 ) from the command line ./gradlew testDebugUnitTest I get the following error (not when I run the same task from Android Studio) java.lang.NoClassDefFoundError: android/content/Context at java.base/java.lang.Class.getDeclaredConstructors0(Native Method) at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3110) at java.base/java.lang

Robolectric throws Resources$NotFoundException when trying to access resource in raw folder

[亡魂溺海] 提交于 2019-12-08 16:05:15
问题 When I try to access a raw resource I receive an android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f060000 error. The resource is a .bks certificate, used for server validation. It is stored on the res/raw folder. The most awkward thing is that when I copied the certificate (and the validation architecture) to a fresh project (that I built just to test this), it worked! I'm using nenick's custom runner, so Robolectric can correctly find the folders for manifest,

Roboletric 4.0.1 keeps throwing Resources$NotFoundException on buildActivity

萝らか妹 提交于 2019-12-08 03:43:45
问题 I am trying to build very simple unittest with roboletric but I can't create the activity. I tried what was suggested on the thread but no success. Resources$NotFoundException when calling Robolectric.buildActivity() Yet, I am using the 4.0.1 version. I wonder if there some extra setup that I need to do. Here's is my gradle: dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support

PowerMock + Robolectric + Dagger2

末鹿安然 提交于 2019-12-08 00:25:35
问题 I test custom view class which contain: android ui elements some logic static methods callings dagger2 dependencies So i use next tools for testing Robolectric for UI elements mocking unit tests for logic testing PowerMock for static methods mocking Robolectric + PowerMock integration problem is known and solution is known - https://github.com/robolectric/robolectric/wiki/Using-PowerMock But with this solution dagger2 dependencies fail. Attention to code. My custom view: public class

How do I specify custom /res directory in Robolectric 2.2?

99封情书 提交于 2019-12-07 23:10:17
问题 My unit tests and my android app live in separate projects. With Robolectric 1, I could specify my /res directory location like so: public class MyTestRunner extends RobolectricTestRunner { public MyTestRunner(Class<?> testClass) throws InitializationError { super(testClass, "../app/AndroidManifest.xml", "../app/res"); } } How do I specify the /res directory location in Robolectric 2.2? 回答1: Use RobolectricTestRunner#getAppManifest(Config): public MyTestRunner(Class<?> testClass) throws

Spurious Test Failures using Picasso and Robolectric

邮差的信 提交于 2019-12-07 17:56:58
问题 I just upgraded to Robolectric 2.1.1 and integrated Picasso today. I now have two test cases that fail randomly (one of these fragments doesn't even use Picasso). If I keep running the tests, everything usually ends up passing (might take a few tries). Test @Before public void setUp() throws Exception { detailActivity = Robolectric.buildActivity( ActivityUnderTest.class ) .withIntent( createIntent() ) .create() .start() .resume() .get(); // Note: The other test case doesn't use the fancy

Activity does not have an options menu

删除回忆录丶 提交于 2019-12-07 15:22:37
问题 I was trying to simulate click on Menu Item present in Toolbar using Robolectric , using the following code ShadowActivity shadowActivity = Shadows.shadowOf(activity); shadowActivity.clickMenuItem(R.id.action_logout); But it is giving me an error: java.lang.RuntimeException: Activity does not have an options menu! Did you forget to call super.onCreateOptionsMenu(menu) Code of the Activity: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView