3

My activity xml contains customeView (TitleToolbar). When I run my unit test, robolectric failed during onCreate method of my Activity creation. The exception details says that it failed to create customeView(TitleToolbar) and throws "Error inflating class"

Error details:

android.view.InflateException: XML file /Users../layout/Myactivity_UI.xml line #-1 (sorry, not yet implemented): Error inflating class com.sample.view.TitleToolbar .... Caused by: java.lang.reflect.InvocationTargetException

here is my xml code:

 <LinearLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="vertical">
         <com.sample.view.TitleToolbar
             android:id="@+id/header"
             android:layout_width="match_parent"
             android:layout_height="wrap_content" />
        <TextView.....
        <TextView..... 
</LinearLayout>

Here is the Test code

 @RunWith(RobolectricTestRunner.class)
 @Config(constants = BuildConfig.class)
 public class SampleTest {

        @Before
        public void setUp() throws NoSuchFieldException, IllegalAccessException {
           ActivityController<MyActivity> activityController = Robolectric.buildActivity(MyActivity.class);
           MyActivity activity = activityController.get();
           activityController.setup();  // this will call onCreate method of activity
.......

here is the activity onCreate code:

@Override
    protected void onCreate(Bundle savedInstanceState) {             
        super.onCreate(savedInstanceState); // this is where robolectric failed to create custom TitleToolbar and throw InflateExcepion. 
AvtarSohi
  • 93
  • 1
  • 8

0 Answers0