我可以做些什么来在Robolectric上对ActiveAndroid的ContentProvider进行一些测试?这个简单的测试失败了
该模型:
@Table(name = "Things")
public class Thing extends Model {
public Thing() {
super();
}
}
Run Code Online (Sandbox Code Playgroud)
考试:
@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));
}
}
Run Code Online (Sandbox Code Playgroud)
生成的堆栈跟踪:
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)
Run Code Online (Sandbox Code Playgroud)
应用程序上下文应该没问题.默认情况下,Robolectric创建清单中显示的应用程序,在本例中为com.activeandroid.Application.
所以,我很困惑为什么Cache中的tableInfo没有被初始化.正常的应用程序执行正常.