简体   繁体   中英

How get the context in Robolectric 3

我能够以这种方式访问​​Robolectric 2.x中的应用程序上下文,但不知道如何在Robolectric 3中执行此操作。

return new ClassThatNeedsAContext(Robolectric.application.getApplicationContext());

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM