I was able to access to the application context in Robolectric 2.x in this way but don't know how to do it in Robolectric 3.
return new ClassThatNeedsAContext(Robolectric.application.getApplicationContext());
properties File. To configure all Robolectric tests within a package or group of packages, create a file named robolectric. properties in the appropriate package. Generally, this file would be placed within the appropriate package directory under src/test/resources in your project tree.
[edited]
Robolectric 2.4-to-3.0-Upgrade-Guide
https://github.com/robolectric/robolectric/wiki/2.4-to-3.0-Upgrade-Guide
[old response] Looking the Robolectric's sample code maybe I found the solution. https://github.com/robolectric/robolectric/blob/f4935bff58ae6a16b1230c3a415973e97713c0fb/robolectric/src/test/java/org/robolectric/shadows/ViewInnerTextTest.java#L22
return new ClassThatNeedsAContext(RuntimeEnvironment.application);
But I have other problems with some libraries so I was't unable to test it yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With