This is due to the use of the Robolectric platform for unit testing on Android. I get a null pointer exception for code that does not have problems during normal operation. I'm just starting out with roboelectric, so it's probably pretty simple.
Here is the challenge code for testing:
@Test public void testInitUtilsInitSequenceNumberIsRandom() { // create an activity for reference InitUtils initUtils = new InitUtils(); // do static initialization to parse questions into memory InitUtils.initialize(initUtils); // <============ the call from roboelectric framework // retreive app state AppState appState = (AppState) initUtils.getApplicationContext(); // fill in later fail("not implemented"); }
Here is a method called inside InitUtils that causes a crash
/ ** * Loads the XML into the member variable {@see mQuestions} * * /
public static void initializeQuestions(Activity activity, AppState appState) { XmlResourceParser questionBatch; Question question = null;
Is there anything special for this to get the resource?
android unit-testing robolectric
Jack beatimble
source share