- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 ActiveAndroid 库来处理数据库。当我创建对象模型时,自动测试因错误而崩溃。
java.lang.NullPointerException
at com.activeandroid.Cache.getTableInfo(Cache.java:148)
at com.activeandroid.Model.<init>(Model.java:54)
at handsfree.penny.mvp.model.Subject.<init>(Subject.java:18)
at handsfree.penny.presenter.subjectlist.SubjectListPresenterTest.createSubjectsList(SubjectListPresenterTest.java:54)
at handsfree.penny.presenter.subjectlist.SubjectListPresenterTest.setup(SubjectListPresenterTest.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
但事实上,我还需要 PowerMockRunner
和 RobolectricGradleTestRunner
。该项目使用 Application 类(它存储在 Component Dagger 上)。这里的选项没有帮助。
第一种情况:
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, manifest = "src/test/TestManifest.xml", sdk = Build.VERSION_CODES.LOLLIPOP)
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*"})
@PrepareForTest({ Cache.class, TableInfo.class, Context.class, ContentResolver.class, ContentProvider.class, ContentValues.class })
@SuppressStaticInitializationFor("com.activeandroid.content.ContentProvider")
public class BaseTest {
@Rule
public PowerMockRule rule = new PowerMockRule();
@Test
public void setup() throws Exception {
PowerMockito.mockStatic(ContentProvider.class);
PowerMockito.when(ContentProvider.createUri(Model.class, 0l)).thenReturn(null);
assertTrue(ContentProvider.createUri(null, null) == null);
}
}
堆栈跟踪:
java.lang.IllegalStateException: Failed to transform class with name android.content.ContentProvider. Reason: cannot find android.content.IContentProvider
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:283)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:192)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:71)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:286)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:192)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:71)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at handsfree.penny.common.BaseTest.setup(BaseTest.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.powermock.modules.junit4.rule.PowerMockStatement$1.run(PowerMockRule.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.java:1899)
at org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:801)
at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:666)
at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:401)
at org.powermock.classloading.AbstractClassloaderExecutor.getResult(AbstractClassloaderExecutor.java:69)
at org.powermock.classloading.AbstractClassloaderExecutor.executeWithClassLoader(AbstractClassloaderExecutor.java:59)
at org.powermock.classloading.SingleClassloaderExecutor.execute(SingleClassloaderExecutor.java:67)
at org.powermock.classloading.AbstractClassloaderExecutor.execute(AbstractClassloaderExecutor.java:43)
at org.powermock.modules.junit4.rule.PowerMockStatement.evaluate(PowerMockRule.java:75)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:251)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: javassist.CannotCompileException: cannot find android.content.IContentProvider
at javassist.CtBehavior.insertBefore(CtBehavior.java:771)
at javassist.CtBehavior.insertBefore(CtBehavior.java:734)
at org.powermock.core.transformers.impl.AbstractMainMockTransformer.modifyMethod(AbstractMainMockTransformer.java:207)
at org.powermock.core.transformers.impl.AbstractMainMockTransformer.allowMockingOfStaticAndFinalAndNativeMethods(AbstractMainMockTransformer.java:112)
at org.powermock.core.transformers.impl.ClassMockTransformer.transformMockClass(ClassMockTransformer.java:56)
at org.powermock.core.transformers.impl.AbstractMainMockTransformer.transform(AbstractMainMockTransformer.java:247)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:264)
... 60 more
Caused by: javassist.NotFoundException: android.content.IContentProvider
at javassist.ClassPool.get(ClassPool.java:452)
at javassist.bytecode.Descriptor.toCtClass(Descriptor.java:592)
at javassist.bytecode.Descriptor.getParameterTypes(Descriptor.java:439)
at javassist.CtBehavior.getParameterTypes(CtBehavior.java:298)
at javassist.CtBehavior.insertBefore(CtBehavior.java:749)
... 66 more
第二种情况:
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
@PowerMockIgnore({ "org.mockito.*", "org.robolectric.*", "android.*" })
@PrepareForTest(ContentProvider.class)
public class MyTest{
@Test
public void testStaticMocking() {
PowerMockito.mockStatic(ContentProvider.class);
PowerMockito.when(ContentProvider.createUri(Model.class, 0l)).thenReturn(null);
assertTrue(ContentProvider.createUri(null, null) == null);
}
}
堆栈跟踪:
org.powermock.api.mockito.ClassNotPreparedException:
The class com.activeandroid.content.ContentProvider not prepared for test.
To prepare this class, add class to the '@PrepareForTest' annotation.
In case if you don't use this annotation, add the annotation on class or method level.
at org.powermock.api.mockito.expectation.reporter.MockitoPowerMockReporter.classNotPrepared(MockitoPowerMockReporter.java:31)
at org.powermock.api.mockito.internal.mockcreation.MockTypeValidatorFactory$DefaultMockTypeValidator.validate(MockTypeValidatorFactory.java:38)
at org.powermock.api.mockito.internal.mockcreation.AbstractMockCreator.validateType(AbstractMockCreator.java:18)
at org.powermock.api.mockito.internal.mockcreation.MockCreator.createMock(MockCreator.java:57)
at org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.java:47)
at org.powermock.api.mockito.PowerMockito.mockStatic(PowerMockito.java:71)
at handsfree.penny.common.DeckardActivityTest.testStaticMocking(DeckardActivityTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:251)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner$2.call(DelegatingPowerMockRunner.java:148)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner$2.call(DelegatingPowerMockRunner.java:140)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner.withContextClassLoader(DelegatingPowerMockRunner.java:131)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner.run(DelegatingPowerMockRunner.java:140)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:121)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
我应该做什么?
最佳答案
对于异常“org.powermock.api.mockito.ClassNotPreparedException:”您可以尝试将此注释放在类声明或测试方法的顶部。
@RunWith(PowerMockRunner.class)@PrepareForTest(CommPortIdentifier.class)
祝一切顺利,
关于java - PowerMock + Robolectric + ActiveAndroid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37473715/
如何在 ActiveAndroid 中添加两列唯一约束?我尝试添加 2.sql 并增加数据库版本,但它似乎没有正确更新(可能是因为我重新安装了应用程序?)。无论如何,有没有办法添加一些注释,我可以在
我想知道是否有可能,以及如何使用“IN”子句在ActiveAndroid中执行where子句。 例如,我想做这样的事情: 新的Select()。from(Table).where(“id in?”,l
我正在使用 ActiveAndroid作为第三方库,以便在 android 中使用 sqlite 数据库,我在使用该库创建和使用新数据库时没有任何问题,但我不知道如何将我自己的现有数据库与该库一起使用
ActiveAndroid 有一个约束,它的所有实体都需要从某个基类继承,并且需要有一个以上下文(来自 Activity )作为输入的单参数构造函数。 [不喜欢这种限制]。 使用 gson,我可以创建
我是 Android 的新手,我正在尝试将 SQLite 与 Active Android ORM 结合使用。我有一个简单的待办事项应用程序,我正在按照教程设置 Activity 的 android。
我学会了在我的 Android 应用程序中使用 ActiveAndroid,谁能告诉我如何只保存具有唯一 ID 的数据?在我的模型中,我将 id 设置为非主键列。这是我的模型类: package co
我的 Android 应用程序正在使用 DB 工具 ActiveAndroid。数据库只是一个简短的本地缓存。所有数据均从服务器重复更新。效果很好。我可以轻松地放下 table 并重新装满它们。 De
我正在使用 ActiveAndroid 并且有两个模型: @Table(name = "Topics") public class Topic extends Model { @Column(name
我想进行最简单的查询,但在网上找不到任何地方如何在 Activity 的 android 中进行查询。 我有一个 Items 表,我只想获取其中的所有项目,但我的查询只返回一个项目。 items1.
我正在尝试使用 ActiveAndroid 来处理我应用中的数据库。 这是我的模型类: package ro.adrian.trivia.datamodel; import java.io.Seria
大家好,作为我类(class)的一部分,我正在尝试测试如何在 android 中使用数据库,但我对这两者都很陌生,所以我在网上找到的大多数帮助都让我有点不知所措。 我想知道如何从表中更新和删除。目前我
我使用图书馆ActiveAndroid with RetroFit . 如果我有一个简单的模型,一切都会很好。但是如果模型包含不同的模型,我不知道所有这些是如何存储在数据库中的 我的模型: @Tabl
我尝试将 ActiveAndroid 添加到我的第一个 Android 应用程序中。到目前为止没有错误,我的项目正在保存(我用 sqlite 管理器检查过)但无论我使用什么查询,结果总是空的。我只有一
伙计们!我写了一个 Book 类,它有 Chapter 对象(一对多关系)。它实现了方法 public List chapters(),如文档中所述。这是 Book.java @Table(name
我正在使用 active android在 Android 上使用 SQLite。 例如,我有以下具有这种结构的 Pets 表: @Table(name = "Pets") public class
我在我的项目中使用 ActiveAndroid 作为 ORM 系统,我使用这行代码对数据库进行查询 List s = new Select() .from(Chats
使用 ActiveAndroid ORM 填充 RecyclerView 和跟踪数据更改的首选方法是什么? 我有 asked a question最近关于这个话题。但是它太冗长了,而且人们又很懒惰,几
我开发了一个 Android 应用程序,我使用 SQLiteOpenHelper 将数据保存在 SQLite 数据库中。 我想知道我是否可以使用 ActiveAndroid 更新我的应用程序,但会保留
您好,我正在开发 Android 应用程序,我在其中使用了 active android。我尝试使用迁移将一列添加到我的表中。我尝试使用以下代码: ALTER TABLE TAGS ADD COLUM
我正在开发一个 Android 应用程序,并考虑使用 ORM 来利用一些数据库工作,我已经看到了一些,它们似乎都适合这项工作,现在我只剩下一个主要问题,我还没有我找到了一种在运行时设置数据库位置的方法
我是一名优秀的程序员,十分优秀!