Robolectric says “AndroidManifest.xml not found”

I’m assuming you’re trying to run the tests with JUnit. You can try two different things: Create a Custom TestRunner class, as shown here. Check the CustomTestRunner section, where you basically create a TestRunner that actually knows the right manifest to use. Specify your tests for them to run with your test runner, with the … Read more

Testing that button starts an Activity with Robolectric

In Robolectric 2.1.1 you can verify if Intent starting new Activity was emitted in following way. @RunWith(RobolectricTestRunner.class) public class MyTest { private ShadowActivity shadowActivity; private MyActivity activity; @Before public void setup() { activity = new MyActivity(); shadowActivity = Robolectric.shadowOf(activity); } @Test public shouldStartNewActivityWhenSomething() { //Perform activity startup //Do some action which starts second activity, for … Read more

Robolectric: Resources$NotFoundException: String resource ID with Android Gradle Plugin 3

As mentioned by an engineer from Google team (most possibly Xavier Ducrohet), Robolectric has issues with AAPT2: Robolectric is not compatible with aapt2. Two options here. First option – follow Robolectric guidelines for Android Studio 3.0+ Add the following to your build.gradle: android { testOptions { unitTests { includeAndroidResources = true } } } Annotate … Read more

Providing test data for SharedPreferences for Robolectric

Found out how – seems so obvious now! For those who are interested, you just get the sharedPreferences, and populate it with the required data. SharedPreferences sharedPreferences = ShadowPreferenceManager.getDefaultSharedPreferences(Robolectric.application.getApplicationContext()); sharedPreferences.edit().putString(“testId”, “12345”).commit(); If you have a custom SharedPreferences, you should be able to do this (haven’t really tested properly, but should also work) SharedPreferences sharedPreferences = … Read more

Where is log output written to when using Robolectric + Roboguice?

I am running robolectric-2.0-alpha-3. What worked for me was to set in the setUp method of my test the stream to stdout Something like: @Before public void setUp() throws Exception { ShadowLog.stream = System.out; //you other setup here } With this version of robolectric I had no success doing the same (ShadowLog.stream = System.out) in … Read more

Android Unit Test with Retrofit2 and Mockito or Robolectric

It is generally not a good idea to test real server requests. See this blog post for an interesting discussion on the topic. According to the author, using your real server is a problem because: Another moving piece that can intermittently fail Requires some expertise outside of the Android domain to deploy the server and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)