I am writing unit testing for a function using roboelectric and facing null pointer exception but I have already assigned the variable. I'm pretty new to this so if any mistake please pardon me.
@Before
public void setup() {
intent = new Intent(context, Xyz.class);
intent.putExtra("abc", "abc");
xyz = Robolectric.buildActivity(Xyz.class, intent)
.create().start().get();
}
@Test
public void onConfigurationChanged() {
int currentOrientation = xyz.getRequestedOrientation();
RelativeLayouot gifframe = xyz.findViewById(R.id.gif_frame);
assertNotNull(gifframe);
assertEquals(gifframe.getVisibility(), VISIBLE);
}
}
I expect thee gifframe to be able to get the visibility but gifframe is returning a null value. everywhere I searched a solution to this is to assign the value before calling it. I have assigned the value in the previous line.