gpt4 book ai didi

android - 如何为 android 启用 AllOpen 插件

转载 作者:行者123 更新时间:2023-12-01 14:38:25 25 4
gpt4 key购买 nike

我正在尝试添加 allopen安卓插件。

我将此添加到我的 build.gradle(.)

ext.kotlin_version = '1.3.61'

classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"

我将此添加到我的 app/build.gradle
apply plugin: 'kotlin-allopen'
apply plugin: 'io.fabric'

allOpen {
annotation('com.myapp.sidemodule.Mockable')
}

由于项目结构,注释位于与属于 App 的模块不同的模块中

我添加了这个
在 sidemodule/debug/Mockable
@Target(AnnotationTarget.ANNOTATION_CLASS)
annotation class Mockable

然后在 sidemodule/debug/OpenClass
@Mockable
@Target(AnnotationTarget.CLASS)
annotation class OpenClass

然后在 sidemodule/release/OpenClass
@Target(AnnotationTarget.CLASS)
annotation class OpenClass

我添加了 @OpenClass到我注定要被 mock 的类(class)
但是,我仍然收到:
E/TestRunner: failed: testCanDetectBadResponse(com.myapp.test.core.SomeTests)
----- begin exception -----
org.mockito.exceptions.base.MockitoException:
Cannot mock/spy class com.myapp.models.MyResponse
Mockito cannot mock/spy because :
- final class
at com.nhaarman.mockitokotlin2.SpyingKt.spy(Spying.kt:52)
at com.myapp.test.core.SomeTests.testCanDetectBadResponse(SomeTests.kt:163)
at java.lang.reflect.Method.invoke(Native Method)
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 androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
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 androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104)
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 org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2189)
----- end exception -----

我如何解决它?

最佳答案

只是在这里尝试同样的事情......这对我有用

我在 build.gradle 中添加了以下内容

allOpen {
annotation('com.mypackage.OpenForTesting')
}

然后创建了 OpenForTesting.kt文件在 com.mypackage包含
@com.mypackage.OpenForTesting
annotation class OpenForTesting

然后最后加了 @OpenForTesting注解
@OpenForTesting
class SomeClassUnderTest {

关于android - 如何为 android 启用 AllOpen 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60025359/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com