mardi 16 août 2016

Gradle TestListener for connectedAndroidTest

Gradle provides the TestListener interface, which can be used with plain, non-Android unit tests:

task listenerTask << {
    def task = tasks.findByName("test")
    task.beforeTest { descriptor ->
        //do something for test start
    }

    task.afterTest { descriptor ->
       //do something for test stop 
    }
}

But I cannot find a way to do something similar with connectedAndroidTest. It gives the error:

Could not find method beforeTest() for arguments      
[build_pwpzptj97xow6oh2r08mqrnf$_run_closure2$_closure5@30db58b4] on task 
'connectedAndroidTest'. 

Probably because connectedAndroidTest doesn't extend org.gradle.api.tasks.testing.Test.

Short of implementing a custom JUnit runner and adding my custom listener, does anyone know of a way to do this? I printed out the methods available on the connectedAndroidTest task object and nothing looks like a listener hook.

Aucun commentaire:

Enregistrer un commentaire