我正在使用Roboelectric和Android注释。下面是我试图运行的简单测试用例:
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk=21)
public class ProjectTest {
public DashboardActivity_ activity;
@Before
public void setUp() {
activity = Robolectric.setupActivity(DashboardActivity_.class);
}
@Test
public void testSaveAnswers() {
assertThat(activity).isNotNull();
}
}
然而,测试在setUp()上失败,并带有以下内容:
android.view.InflateException: XML file build\intermediates\res\merged\tst\debug\layout\dashboard.xml line #-1 (sorry, not yet implemented): Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
似乎在抱怨我的主要活动的XML布局文件。我似乎并不喜欢我正在使用<片段>标签
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="Projects"/>
<fragment
android:tag="estimator_list_fragment"
android:name="com.myapp.fragments.EstimatorListFragment_"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/estimate_list"
tools:layout="@layout/estimate_list"/>
</LinearLayout>
</RelativeLayout>
我看了很多处理类似问题的帖子,但其他已知的解决方案都没有对我有用。