Reputation: 291
I am very much new to Robolectric. I am facing these issues after migrating from Robolectric v3.0 to v3.4.1.
AppController
class which extends Application
RuntimeEnvironment.application
to my AppController
, which shouldn't be the case as my AppController
extends Application
and was working fine before migrating to latest version. Please find the code below for my test
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, manifest = "app/src/main/AndroidManifest.xml", sdk = 21)
public class FragmentTest {
private ExampleFragment fragment = SupportFragmentController.of(new ExampleFragment()).create().get();
private Context mContext;
@Before
public void setUp() throws Exception {
// RuntimeEnvironment.application.onCreate();
mContext =RuntimeEnvironment.application ;
}
@Test
public void testFragmentInstantiation() {
ExampleFragment.mAppController = (AppController)mContext;
}
To reproduce - run any test.
Robolectric version is 3.4.1.
Upvotes: 1
Views: 523
Reputation: 20130
The main advice is to do not put manifest file location in the @Config
section unless you know what you're doing. So please change your test annotations to:
@Config(constants = BuildConfig.class, sdk = 21)
Also, I don't know if it is by purpose but you could use much newer android sdk in your test with the newest version of Robolectric
Upvotes: 1