我的活动xml包含customeView(TitleToolbar)。当我运行单元测试时,robolectric在我的Activity创建的onCreate方法中失败。异常详细说明它无法创建customeView(TitleToolbar)并抛出"错误导致类"
错误详情:
android.view.InflateException:XML文件 /Users../layout/Myactivity_UI.xml line#-1(对不起,还没有 实现):错误膨胀类com.sample.view.TitleToolbar .... 引起: java.lang.reflect.InvocationTargetException
这是我的xml代码:
<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>
这是测试代码
@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
.......
这是活动onCreate代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // this is where robolectric failed to create custom TitleToolbar and throw InflateExcepion.