RobolectricのActiveAndroidのContentProviderでいくつかのテストカバレッジを取得するにはどうすればよいですか?この簡単なテストは失敗します。RobolectricでActiveAndroidをテストする
モデル:
@Table(name = "Things")
public class Thing extends Model {
public Thing() {
super();
}
}
試験:
@RunWith(RobolectricTestRunner.class)
public class ContentProviderTest {
@Test
public void itShouldQuery() throws Exception {
new Thing().save();
ContentResolver cr = new MainActivity().getContentResolver();
assertNotNull(
cr.query(Uri.parse("content://org.example/things"),
null, null, null, null));
}
}
得られたスタックトレース:
java.lang.NullPointerException: null
at com.activeandroid.Cache.getTableInfo(Unknown Source)
at com.activeandroid.Model.<init>(Unknown Source)
at org.example.Thing.<init>(Thing.java:9)
at org.example.ProviderTest.itShouldQuery(ProviderTest.java:25)
アプリケーション・コンテキストがOKであるべきです。デフォルトでは、Robolectricはマニフェストに表示されるアプリケーションを作成します。この場合、com.activeandroid.Applicationです。
私は、なぜキャッシュのtableInfoが初期化されていないのか疑問に思います。通常のアプリケーションの実行は正常に動作します。
どのIDEを使用していますか? Eclipseの回避策についてはオープンバグがありますが、intellijではありません。 https://github.com/pardom/ActiveAndroid/issues/63 – Joe
Eclipseで動作します。私は 'mvn test'したいです。 –
これは、MavenはActiveAndroidが期待している以外のフォルダにビルドするため、同じ問題が発生します。モデルを自動的に検索するのではなく、登録するためにActiveAndroidを変更するのは難しいことではありません。 – Joe