Android studio 模拟RealmObject类出错

Android studio 模拟RealmObject类出错,android-studio,realm,mockito,Android Studio,Realm,Mockito,在Mockito中进行测试时,我无法理解如何使用模型领域的类。如果该类是从RealmObjec继承的 public class Foo extends RealmObject { @PrimaryKey private String PK; public Stuff getStuff(){ return new Stuff(); } public int getNum(){ return 1; } } 包装在模拟测试中 @Test public void clearObj

在Mockito中进行测试时,我无法理解如何使用模型领域的类。如果该类是从RealmObjec继承的

public class Foo extends RealmObject {

@PrimaryKey
private String PK;

public Stuff getStuff(){
    return new Stuff();
}

public int getNum(){
    return 1;
}
}
包装在模拟测试中

@Test
public void clearObject(){
    Foo mock = mock(Foo.class);
}
即使我穿上了间谍装

 @Test
public void SpyOnRealmObject(){
    Foo foo = new Foo();
    Foo spy_foo = spy(foo);
}
运行测试时出错:

    org.mockito.exceptions.base.MockitoException: 
Mockito cannot mock this class: class ru.arvalon.coffeeorder.trash.Foo.

If you're not sure why you're getting this error, please report to the mailing list.


Java               : 1.8
JVM vendor name    : JetBrains s.r.o
JVM vendor version : 25.152-b02
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 1.8.0_152-release-1024-b02
JVM info           : mixed mode
OS name            : Windows 8.1
OS version         : 6.3


You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.

Underlying exception : org.mockito.exceptions.base.MockitoException: Could not modify all classes [class java.lang.Object, class ru.arvalon.coffeeorder.trash.Foo, class io.realm.RealmObject, interface io.realm.RealmModel, interface io.realm.internal.ManagableObject]

at ru.arvalon.coffeeorder.mainpage.RealmCheck.RealmObject(RealmCheck.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...

Caused by: org.mockito.exceptions.base.MockitoException: Could not modify all classes [class java.lang.Object, class ru.arvalon.coffeeorder.trash.Foo, class io.realm.RealmObject, interface io.realm.RealmModel, interface io.realm.internal.ManagableObject]
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355)
... 28 more
build.gradle中的节没有帮助

android {
testOptions {
    unitTests.all {
        jvmArgs '-noverify'
    }
}
}

请显示Mockito依赖项和Realm versionproject build.gradle:dependencies{classpath'com.android.tools.build:gradle:3.1.0'classpath“io.Realm:Realm gradle plugin:5.0.0”}应用程序级build.gradle:apply plugin:'com.android.application'apply plugin:'Realm android'。。。依赖项{testImplementation'junit:junit:4.12'androidTestImplementation'com.android.support.test:runner:1.0.1'testImplementation'org.mockito:mockito核心:2.17.0'testImplementation'org.robollectric:robollectric:3.8'androidTestImplementation'com.android.support.test.espresso:espresso核心:3.0.1'}