代码之家  ›  专栏  ›  技术社区  ›  Sean Shi

如何在Firebase测试实验室中执行指定的测试套件类

  •  4
  • Sean Shi  · 技术社区  · 7 年前

    我有一个像这样的浓缩咖啡测试套件课程

    package instrumentedtest;
    
    import org.junit.ClassRule;
    import org.junit.rules.ExternalResource;
    import org.junit.runner.RunWith;
    import org.junit.runners.Suite;
    
    @RunWith(Suite.class)
    @Suite.SuiteClasses({
            Test1.class,
            Test2.class,
            Test3.class
    })
    
    public class POSRuleSuite {
        @ClassRule
        public static ExternalResource testRule = new ExternalResource() {
            @Override
            protected void before() throws Throwable {
                System.out.println("Testing starts.........");
            }
    
            @Override
            protected void after() {
                System.out.println("Testing ends.........");
            }
        };
    }
    

    我在Android Studio中使用这个套件类设置了Firebase测试。我从Android Studio启动了这个firebase测试,它确实有效。

    enter image description here

    但是当我用Gcloud命令从命令行启动它时,我没有执行测试。

    gcloud firebase test android run ^
        --type instrumentation ^
        --app POS.apk ^
        --test POS-debug-androidTest.apk ^
        --test-runner-class=org.junit.runners.Suite ^
        --test-targets=instrumentedtest.POSRuleSuite ^
        --device model=Nexus10,version=22,locale=en,orientation=landscape ^
        --timeout 300s
    

    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 [https://console.developers.google.com/storage/browser/test-lab-j9zwyqscmy0rw-k53tazzivjxvu/2017-10-19_14:25:20.055000_jPmA/]
    
    ERROR: (gcloud.firebase.test.android.run) Http error while creating test matrix: ResponseError 400: Invalid test target for instrumentation test: instrumentedtest.POSRuleSuite
    
    C:\git\POS>
    

    有人知道如何让它工作吗?

    感谢您的帮助。

    1 回复  |  直到 7 年前
        1
  •  6
  •   heronsanches    4 年前

    我找到了原因,我们要通知的类型 测试目标 . 在这种情况下,类型为

    --test-targets="class instrumentedtest.POSRuleSuite"
    

    您还可以传递一个包含所有目标的字符串列表,用逗号分隔,例如:

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

    Firebase doc reference

    gcloud firebase test android run ^
        --type instrumentation ^
        --app POS.apk ^
        --test POS-debug-androidTest.apk ^
        --test-targets="class instrumentedtest.POSRuleSuite" ^
        --device model=Nexus10,version=22,locale=en,orientation=landscape ^
        --timeout 300s