java Android UI测试崩溃,但应用运行良好
所以我正在创建一个示例项目,它使用这个库https://github.com/OmerUygurOzer/Knit(我创建的东西)
问题是,测试不会与它一起运行。不知道为什么。应用程序本身运行良好。但是当我运行测试时,它就在应用程序类内部调用Knit.init(this);
的那一行出错了
这是logcat
02-13 20:46:20.471 23727-23727/com.omerozer.knitmvpexample W/System.err: java.lang.NoSuchMethodException: <init> [interface com.omerozer.knit.InternalModel]
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at java.lang.Class.getConstructor(Class.java:531)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at java.lang.Class.getConstructor(Class.java:495)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at com.omerozer.knit.KnitClassLoader.getViewToPresenterConstructor(KnitClassLoader.java:64)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at com.omerozer.knit.KnitClassLoader.getViewToPresenterMap(KnitClassLoader.java:79)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at com.omerozer.knit.KnitClassLoader.<init>(KnitClassLoader.java:23)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at com.omerozer.knit.Knit.init(Knit.java:28)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at com.omerozer.knitmvpexample.MVPApp.onCreate(MVPApp.java:16)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at 安卓.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at 安卓.support.test.runner.MonitoringInstrumentation.callApplicationOnCreate(MonitoringInstrumentation.java:382)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at 安卓.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at 安卓.app.ActivityThread.access$1500(ActivityThread.java:151)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at 安卓.os.Handler.dispatchMessage(Handler.java:102)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at 安卓.os.Looper.loop(Looper.java:135)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at 安卓.app.ActivityThread.main(ActivityThread.java:5254)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at java.lang.reflect.Method.invoke(Native Method)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:698)
02-13 20:46:20.473 23727-23727/com.omerozer.knitmvpexample E/InstrumentationResultPrinter: Failed to mark test No Tests as finished after process crash
02-13 20:46:20.473 23727-23727/com.omerozer.knitmvpexample E/MonitoringInstr: Exception encountered by: com.omerozer.knitmvpexample.MVPApp@3a68f1a5. Dumping thread state to outputs and pining for the fjords.
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[])' on a null object reference
at com.omerozer.knit.KnitClassLoader.getViewToPresenterMap(KnitClassLoader.java:79)
at com.omerozer.knit.KnitClassLoader.<init>(KnitClassLoader.java:23)
at com.omerozer.knit.Knit.init(Knit.java:28)
at com.omerozer.knitmvpexample.MVPApp.onCreate(MVPApp.java:16)
at 安卓.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
at 安卓.support.test.runner.MonitoringInstrumentation.callApplicationOnCreate(MonitoringInstrumentation.java:382)
at 安卓.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
at 安卓.app.ActivityThread.access$1500(ActivityThread.java:151)
at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at 安卓.os.Handler.dispatchMessage(Handler.java:102)
at 安卓.os.Looper.loop(Looper.java:135)
at 安卓.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
错误消息如下:
Started running tests
Test running failed: Instrumentation run failed due to java.lang.NullPointerException
似乎测试环境找不到init方法??这对我来说毫无意义
这是gradle的设置
apply plugin: 'com.安卓.application'
安卓 {
compileSdkVersion 26
defaultConfig {
applicationId "com.omerozer.knitmvpexample"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "安卓.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-安卓.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.安卓.support:appcompat-v7:26.1.0'
implementation 'com.安卓.support.constraint:constraint-layout:1.0.2'
implementation 'com.安卓.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
安卓TestImplementation 'com.安卓.support.test:runner:1.0.1'
安卓TestImplementation 'com.安卓.support.test.espresso:espresso-core:3.0.1'
安卓TestImplementation 'com.github.OmerUygurOzer.knit:knitlib:v1.0.2'
安卓TestAnnotationProcessor 'com.github.OmerUygurOzer.knit:knitprocessor:v1.0.2'
implementation 'com.github.OmerUygurOzer.knit:knitlib:v1.0.2'
annotationProcessor 'com.github.OmerUygurOzer.knit:knitprocessor:v1.0.2'
安卓TestCompile 'com.安卓.support.test.espresso:espresso-core:3.0.1'
安卓TestCompile 'com.安卓.support.test:runner:1.0.1'
}
共 (0) 个答案