Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get the context in Robolectric 3

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());
like image 969
Antonio Jose Avatar asked Jan 08 '15 00:01

Antonio Jose


People also ask

Where do you put Robolectric properties?

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.


1 Answers

[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.

like image 166
Antonio Jose Avatar answered Sep 21 '22 16:09

Antonio Jose