Java Android用户界面测试崩溃,但应用运行良好
所以我正在创建一个使用这个库(我创建的东西)的示例项目 问题是,测试不会与它一起运行。不知道为什么。应用程序本身运行良好。但是当我运行测试时,它就在Java Android用户界面测试崩溃,但应用运行良好,java,android,automated-tests,android-espresso,Java,Android,Automated Tests,Android Espresso,所以我正在创建一个使用这个库(我创建的东西)的示例项目 问题是,测试不会与它一起运行。不知道为什么。应用程序本身运行良好。但是当我运行测试时,它就在Knit.init(this)行出错了在应用程序类内部调用 这是logcat 02-13 20:46:20.471 23727-23727/com.omerozer.knitmvpexample W/System.err: java.lang.NoSuchMethodException: <init> [interface com.ome
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 android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at android.support.test.runner.MonitoringInstrumentation.callApplicationOnCreate(MonitoringInstrumentation.java:382)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at android.app.ActivityThread.access$1500(ActivityThread.java:151)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at android.os.Looper.loop(Looper.java:135)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at android.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.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
02-13 20:46:20.472 23727-23727/com.omerozer.knitmvpexample W/System.err: at com.android.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 android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
at android.support.test.runner.MonitoringInstrumentation.callApplicationOnCreate(MonitoringInstrumentation.java:382)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.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.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
似乎测试环境找不到init方法??这对我来说毫无意义
这是gradle的设置
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.omerozer.knitmvpexample"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestImplementation 'com.github.OmerUygurOzer.knit:knitlib:v1.0.2'
androidTestAnnotationProcessor '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'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestCompile 'com.android.support.test:runner:1.0.1'
}
这正是浓缩咖啡中发生的事情
Android JUnit runner在应用程序运行的同一进程中运行。
如果您的应用程序中存在运行时异常(例如),它将中断整个检测过程
我在手动运行应用程序时注意到了这一点。当运行仪器测试时,它工作得很好,但在某个时候,仪器崩溃了
经过进一步调查,我注意到我们在应用程序中使用的模块中存在一个错误
如果希望避免仪器崩溃的情况,可以使用(查看演示文稿)。以这种方式运行测试时,将出现孤立的崩溃
如果可以修复代码中发生的关键异常,只需执行:-)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.omerozer.knitmvpexample"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestImplementation 'com.github.OmerUygurOzer.knit:knitlib:v1.0.2'
androidTestAnnotationProcessor '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'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestCompile 'com.android.support.test:runner:1.0.1'
}