After upgrading to Java 8 and build tool version 25, the Android test case failed
I have a bunch of normal test cases However, once my project is updated to build tool version 25 and Java has been updated to JDK 1.8, all my test cases will fail
When I run my tests, I use/ Gradlew cat, I received an error message:
Because 'Java Lang. NullPointerException 'causes the detection run to fail com android. builder. testing. Connecteddevice > no tests found [nexus 6 – 6.0.1] failed
or
For nexus 6 – 6.0 1 test failed: due to 'Java Lang. classnotfoundexception 'causes instrument operation failure
com. android. builder. testing. Connecteddevice > no tests found [nexus 6 – 6.0.1] failed
My build Gradle has the following lines:
androidTestCompile 'junit:junit:4.12' androidTestCompile 'com.android.support.test:runner:0.4' androidTestCompile 'com.android.support.test:rules:0.4' androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
Know what the solution might be?
to update:
When I try to use it/ When gradlew - Cat - s runs the same operation from gradle, I see the following exception:
Cause: Java Lang.noclassdeffounderror: org / gradle / logging / consolerenderer on COM android. build. gradle. internal. tasks. DeviceProviderInstrumentTestTask. Runtests (deviceproviderinstrumenttesttask. Java: 140) is available at org gradle. internal. reflect. JavaMethod. invoke(JavaMethod.java:75) at org. gradle. api. internal. project. taskfactory. AnnotationProcessingTaskFactory $StandardTaskAction. Doexecute (annotationprocessingtaskfactory. Java: 228) is available at org gradle. api. internal. project. taskfactory. AnnotationProcessingTaskFactory $StandardTaskAction. execute(AnnotationProcessingTaskFactory.java:221) at org. gradle. api. internal. project. taskfactory. AnnotationProcessingTaskFactory $StandardTaskAction. Execute (annotationprocessingtaskfactory. Java: 210) is available at org gradle. api. internal. AbstractTask $TaskActionWrapper. Execute (abstracttask. Java: 621) is available at org gradle. api. internal. AbstractTask $TaskActionWrapper. execute(AbstractTask.java:604) at org. gradle. api. internal. tasks. execution. ExecuteActionsTaskExecuter. Executeaction (executeactionstakesecuter. Java: 80) is available at org. Org gradle. api. internal. tasks. execution. ExecuteActionsTaskExecuter. Executeactions (executeactionstakeexecuter. Java: 61)... 68 more
Google search told me that this might be a special problem, but my tests worked well in the same gradle version
Solution
It turns out that during my basic context initialization, the root cause is a null pointer!
My study:
>Whether we use ide or gradle to run test cases, they will eventually call the AM instrumentation command( https://developer.android.com/studio/test/command-line.html ). > run the command ADB shell am instrument - W - R - e debug true - E class (note that I have set debug to true). > At the same time, let your ADB logcat run This tells me why I met NPE