N
N
Neic2015-10-13 08:51:37
Android
Neic, 2015-10-13 08:51:37

Why doesn't Robolectric call onCreate()?

I'm trying to write tests using Robolectric, but the trouble is that it does not call onCreate () and other life methods of activation, or it just calls it is not clear how. For when I further use variables / objects that must be initialized, then my tests crash with NPE, because during the test there was an attempt to access a NULL object. Judging from what I understood, onCreate () was not called correctly. Tried to go through the lifecycle in the following ways:
1)

MainActivity activity = Robolectric.buildActivity(MainActivity.class).create().start().resume().get();

2)
MainActivity activity = Robolectric.setupActivity(MainActivity.class)

None of them work. What could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question