testing - Gradle build fails with "String Index out of range" when Android Tests Fail -


i experiencing problem when trying instrumentation tests android. when 1 of tests fails, build fails, doesn't state test failed. instead failure: build failed exception. went wrong section, string index out of range: -1.

in real app, causing not generate html report either, , xml report sporadically generated. have put simple test case, generating report, otherwise giving same failure message.

to clarify, the test designed fail, expect a test has failed message instead of looks different failure reason. suspect failure causing else in build lifecycle go wrong leading message seeing.

here simple test app

build.gradle

buildscript {     repositories {         jcenter()         mavencentral()     }     dependencies {         classpath 'com.android.tools.build:gradle:2.4.0-alpha7'     } }  apply plugin: 'com.android.application'  repositories {     jcenter()     mavencentral() }  dependencies {     androidtestcompile "com.android.support.test.espresso:espresso-core:2.2.2"     androidtestcompile "com.android.support.test.espresso:espresso-intents:2.2.2"     androidtestcompile "com.android.support.test:runner:0.5" }  android {     compilesdkversion 24     buildtoolsversion '25.0.2'      defaultconfig {         testinstrumentationrunner "android.support.test.runner.androidjunitrunner"     }      compileoptions {         sourcecompatibility javaversion.version_1_8         targetcompatibility javaversion.version_1_8      }      buildtypes {                 release {             minifyenabled true             proguardfile getdefaultproguardfile('proguard-android.txt')         }     } } 

src/main/androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"       package="com.test.bad"       android:versioncode="1"       android:versionname="1">     <uses-sdk android:minsdkversion="24" android:targetsdkversion="24" />          <application android:label="bad">         <activity android:name="badtestactivity" android:label="bad">             <intent-filter>                 <action android:name="android.intent.action.main" />                 <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>     </application> </manifest> 

src/main/java/test/bad/badtestactivity.java

package com.test.bad;  import android.app.activity; import android.os.bundle;  public class badtestactivity extends activity {      /** called when activity first created. */     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);     } } 

src/androidtest/java/com/test/bad/badtest.java

package com.test.bad;  import org.junit.test; import org.junit.runner.runwith; import static org.junit.assert.fail; import android.support.test.runner.androidjunit4;  @runwith(androidjunit4.class) public class badtest {      @test     public void failtest() {         fail("this test fails");     }  } 

when run gradle connectedandroidtest, see

:connecteddebugandroidtest  failure: build failed exception.  * went wrong: string index out of range: -1  * try: run --stacktrace option stack trace.  run --info or --debug  option more log output. 

i expect give message build failing because of failed test instead of strange string index. in real application (which uses kotlin , mockito in tests) report html not generated (there many more tests, , think has lack of report).

using --info or --debug doesn't seem show useful, using --stacktrace shows

* exception is: java.lang.stringindexoutofboundsexception: string index out of range: -1     @ java.lang.string.substring(string.java:1967)     @ org.gradle.internal.logging.text.abstractlinechoppingstyledtextoutput$statecontext.flushlinetext(abstractlinechoppingstyledtextoutput.java:115)     @ org.gradle.internal.logging.text.abstractlinechoppingstyledtextoutput$2.execute(abstractlinechoppingstyledtextoutput.java:167)     @ org.gradle.internal.logging.text.abstractlinechoppingstyledtextoutput$2.execute(abstractlinechoppingstyledtextoutput.java:160)     @ org.gradle.internal.logging.text.abstractlinechoppingstyledtextoutput$1.execute(abstractlinechoppingstyledtextoutput.java:146)     @ org.gradle.internal.logging.text.abstractlinechoppingstyledtextoutput$1.execute(abstractlinechoppingstyledtextoutput.java:131)     @ org.gradle.internal.logging.text.abstractlinechoppingstyledtextoutput.doappend(abstractlinechoppingstyledtextoutput.java:41)     @ org.gradle.internal.logging.text.abstractstyledtextoutput.text(abstractstyledtextoutput.java:73)     @ org.gradle.internal.logging.text.abstractstyledtextoutput.println(abstractstyledtextoutput.java:68)     @ org.gradle.internal.logging.events.logevent.render(logevent.java:48)     @ org.gradle.internal.logging.console.styledtextoutputbackedrenderer.onoutput(styledtextoutputbackedrenderer.java:65)     @ org.gradle.internal.logging.sink.progresslogeventgenerator.dooutput(progresslogeventgenerator.java:72)     @ org.gradle.internal.logging.sink.progresslogeventgenerator.onoutput(progresslogeventgenerator.java:62)     @ org.gradle.internal.logging.console.buildloglevelfilterrenderer.onoutput(buildloglevelfilterrenderer.java:42)     @ org.gradle.internal.logging.sink.outputeventrenderer$4.onoutput(outputeventrenderer.java:265)     @ org.gradle.internal.logging.sink.outputeventrenderer$lazylistener.onoutput(outputeventrenderer.java:368)     @ sun.reflect.generatedmethodaccessor1.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:498)     @ org.gradle.internal.dispatch.reflectiondispatch.dispatch(reflectiondispatch.java:35)     @ org.gradle.internal.dispatch.reflectiondispatch.dispatch(reflectiondispatch.java:24)     @ org.gradle.internal.event.abstractbroadcastdispatch.dispatch(abstractbroadcastdispatch.java:42)     @ org.gradle.internal.event.broadcastdispatch$singletondispatch.dispatch(broadcastdispatch.java:230)     @ org.gradle.internal.event.broadcastdispatch$singletondispatch.dispatch(broadcastdispatch.java:149)     @ org.gradle.internal.event.abstractbroadcastdispatch.dispatch(abstractbroadcastdispatch.java:58)     @ org.gradle.internal.event.broadcastdispatch$compositedispatch.dispatch(broadcastdispatch.java:324)     @ org.gradle.internal.event.broadcastdispatch$compositedispatch.dispatch(broadcastdispatch.java:234)     @ org.gradle.internal.event.listenerbroadcast.dispatch(listenerbroadcast.java:140)     @ org.gradle.internal.event.listenerbroadcast.dispatch(listenerbroadcast.java:37)     @ org.gradle.internal.dispatch.proxydispatchadapter$dispatchinginvocationhandler.invoke(proxydispatchadapter.java:93)     @ com.sun.proxy.$proxy0.onoutput(unknown source)     @ org.gradle.internal.logging.sink.outputeventrenderer.onoutput(outputeventrenderer.java:334)     @ org.gradle.launcher.daemon.client.daemonclient.monitorbuild(daemonclient.java:216)     @ org.gradle.launcher.daemon.client.daemonclient.executebuild(daemonclient.java:178)     @ org.gradle.launcher.daemon.client.daemonclient.execute(daemonclient.java:141)     @ org.gradle.launcher.daemon.client.daemonclient.execute(daemonclient.java:92)     @ org.gradle.launcher.cli.runbuildaction.run(runbuildaction.java:51)     @ org.gradle.internal.actions$runnableactionadapter.execute(actions.java:173)     @ org.gradle.launcher.cli.commandlineactionfactory$parseandbuildaction.execute(commandlineactionfactory.java:287)     @ org.gradle.launcher.cli.commandlineactionfactory$parseandbuildaction.execute(commandlineactionfactory.java:260)     @ org.gradle.launcher.cli.javaruntimevalidationaction.execute(javaruntimevalidationaction.java:33)     @ org.gradle.launcher.cli.javaruntimevalidationaction.execute(javaruntimevalidationaction.java:24)     @ org.gradle.launcher.cli.exceptionreportingaction.execute(exceptionreportingaction.java:33)     @ org.gradle.launcher.cli.exceptionreportingaction.execute(exceptionreportingaction.java:22)     @ org.gradle.launcher.cli.commandlineactionfactory$withlogging.execute(commandlineactionfactory.java:253)     @ org.gradle.launcher.cli.commandlineactionfactory$withlogging.execute(commandlineactionfactory.java:182)     @ org.gradle.launcher.main.doaction(main.java:33)     @ org.gradle.launcher.bootstrap.entrypoint.run(entrypoint.java:45)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:498)     @ org.gradle.launcher.bootstrap.processbootstrap.runnoexit(processbootstrap.java:60)     @ org.gradle.launcher.bootstrap.processbootstrap.run(processbootstrap.java:37)     @ org.gradle.launcher.gradlemain.main(gradlemain.java:23) 

i using windows 7, gradle 4.0 (the problem exists 3.5 well) , java 8. running tests on physical device - samsung galaxy s6 running nougat 7.0.

what causing error message? should see?

it seems known issue gradle on windows. there similar error description reported issue 2077 , fix issued (apparently caused multiple \r characters). there note issue fixed in gradle 4.1.

update: 4.1 out, , seems have been fixed. simple app above behaves expected, , real app had problem behaves expected.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -