How to execute a designated test suite class in Firebase Test Lab


I have an espresso test suite class like this

package instrumentedtest;

import org.junit.ClassRule;
import org.junit.rules.ExternalResource;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;


public class POSRuleSuite {
    public static ExternalResource testRule  new ExternalResource() {
        protected void before() throws Throwable {
            System.out.println("Testing starts.........");

        protected void after() {
            System.out.println("Testing ends.........");

I set up a Firebase test with this suite class in Android Studio. I launch this firebase test from Android Studio and it does work.

enter image description here

But I failed to execute the test when I launch it from command line with Gcloud command.

gcloud firebase test android run ^
    --type instrumentation ^
    --app POS.apk ^
    --test POS-debug-androidTest.apk ^
    --test-runner-classorg.junit.runners.Suite ^
    --test-targetsinstrumentedtest.POSRuleSuite ^
    --device modelNexus10,version22,localeen,orientationlandscape ^
    --timeout 300s

Here is output

Uploading [POS.apk] to Firebase Test Lab...
Uploading [POS-debug-androidTest.apk] to Firebase Test Lab...
Raw results will be stored in your GCS bucket at []

ERROR: ( Http error while creating test matrix: ResponseError 400: Invalid test target for instrumentation test: instrumentedtest.POSRuleSuite


Does anyone know how to get it work?

Any help is appreciated.


I found the reason, We have to inform the type of the test-targets. In this case the type is class. So that line should be in this way.

--test-targets"class instrumentedtest.POSRuleSuite"

You can also pass a string list with all yours targets, separated by comma, e.g.:

--test-targets"class instrumentedtest.POSRuleSuite,class instrumentedtest.AnotherRuleSuite"

Firebase doc reference

Here the full request.

gcloud firebase test android run ^
    --type instrumentation ^
    --app POS.apk ^
    --test POS-debug-androidTest.apk ^
    --test-targets"class instrumentedtest.POSRuleSuite" ^
    --device modelNexus10,version22,localeen,orientationlandscape ^
    --timeout 300s

Answered By – Sean Shi

Leave a Comment