I\'m trying to run unit tests with Robolectric 2.1.1 and I cannot get it to inflate custom layouts (e.g. ViewPagerIndicator classes). Suppose this is my layout:
<
mTestRoboActivityView = LayoutInflater.from(new Activity()).inflate(R.layout.test, null);
In this line of code you used 'new Activity()' means instance of new Activity, that not for your current Activity. You can resolve this issue by passing instance on current Activity. Use like this-
public class TestRoboActivityTest {
private View mTestRoboActivityView;
private Context mContext;
public TestRoboActivityTest(Context mContext){
this.mContext=mContext;
}
@Before
public void setUp() throws Exception {
mTestRoboActivityView = (LayoutInflater.from(mContext)).inflate(R.layout.test, null);
}
@After
public void tearDown() throws Exception {
mTestRoboActivityView = null;
}
@Test
public void testSanity() throws Exception {
Assert.assertNotNull(mTestRoboActivityView);
}}
I am not sure that above code working fine but use for reference, instance of current Activity. Refer it may be help you.