Giter Site home page Giter Site logo

gildor / gradle-firebase-test-lab-plugin Goto Github PK

View Code? Open in Web Editor NEW
19.0 5.0 2.0 182 KB

Gradle plugin for Firebase Test Lab

License: Apache License 2.0

Kotlin 100.00%
gradle-plugin gcloud firebase firebase-test-lab espresso android android-instrumentation-tests

gradle-firebase-test-lab-plugin's Introduction

Gradle plugin for Firebase Test Lab

License CircleCI

This is experimental Gradle plugin for Firebase Test Lab

Prerequirements:

Configuration

//Add dependency to your build script
buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "gradle.plugin.ru.gildor.gradle.firebase.testlab:firebase-test-lab:0.1.1"
    }
}

//Apply plugin in your target Android projet
apply plugin: 'firebase-test-lab'

//Configure plugin
firebaseTestLab {
    // [REQUIRED] Path to Google Cloud SDK CLI tools - https://cloud.google.com/sdk/gcloud/
    gcloudPath = "/Library/google-cloud-sdk/bin/"
    // [REQUIRED] Google Cloud Storage bucket name to keep test results
    bucketName = "android_ci"
    // `false` by default
    ignoreFailures = false
    // Plugin will create tasks not only for each your build variant, 
    // but also without dependency on current project app build, 
    // this allow you to run tests with configured matrices for any pair of apk and test apk
    // You must pass path to apk and testApk as gradle build parameters -Papk and -PtestApk. false by default 
    enableVariantLessTasks = false
    // Configuration that allows to download test result artifacts to build dir
    copyArtifact {
        // Test results in junit XML result format. true by default
        junit = true
        // File with Android logs. false by default
        logcat = false
        // Video of test. false by default
        video = false
        // Test results in test lab format (plain text log file)
        instrumentation = false
    }
    // Configuration of your matrices. Plugin creates 2 tasks for each matrix (for instrumentation and robo tests)
    matrices {
        // Name of matrix (test configuration)
        // How to choose configuration:
        // https://firebase.google.com/docs/test-lab/command-line#choosing_test_configurations
        nexus7 {
            // [REQUIRED] API level of devices
            androidApiLevels = [19, 21]
            // [REQUIRED] Names of devices.
            deviceIds = ["flo"]
            // Locale. "en" by default
            locales = ["en"]
            // Orientation of device. Can be `portrait` or `landscape`. Portrait by default
            orientations = ["portrait", "landscape"]
            // Maximum test length. No timeout by default
            timeoutSec = 0
        }
        // Example of minimal matrix configuration for 1 device (Nexus 5 with API Level 21)
        nexus5 {
            androidApiLevels = [21]
            deviceIds = ["hammerhead"]
        }
    }
}

Example of configuration for Gradle Script Kotlin (for version 0.7)

import ru.gildor.gradle.firebase.testlab.*
import ru.gildor.gradle.firebase.testlab.Orientation.*

apply {
    plugin<FirebaseTestLabPlugin>()
}

configure<FirebaseTestLabPlugin> {
    gcloudPath = "/Library/google-cloud-sdk/bin/"
    bucketName = "android_ci"
    ignoreFailures = true
    copyArtifact {
        junit = true
        logcat = true
    }
    matrices {
        "nexus7" {
            androidApiLevels = listOf(19, 21)
            deviceIds = listOf("flo")
            locales = listOf("en")
            orientations = listOf(portrait, landscape)
        }
    }
}

Run tests

To run tests you should use one of plugin tasks

./gradlew test<BuildVariant><MatrixName><TestType>TestLab

For example:

./gradlew testDebugNexus5InstrumentationTestLab

Will be started instrumentation test for debug build (no flavor) for matrix with name nexus5

TODO:

  • Sample app
  • Tests
  • Maybe some additional settings from gcloud CLI
  • Find way to avoid gcloud CLI and use pure Java API to upload files (need investigation) and download copyArtifact (definitely possible)
  • Task to print possible matrix settings from gcloud

gradle-firebase-test-lab-plugin's People

Contributors

gildor avatar meoyawn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gradle-firebase-test-lab-plugin's Issues

Support for directories-to-pull and environment-variables

In order to generate coverage of e.g. Espresso tests, it's necessary to make the following adjustments:

  • set testCoverageEnabled true in build.gradle > android > buildTypes > [buildType] block
    (minifyEnabled has to be false)
  • add --environment-variables coverage=true,coverageFile=/sdcard/coverage/somefile to gcloud cmdline (see documentation)
  • add --directories-to-pull /sdcard/coverage to gcloud cmdline (so that the files will be pulled into artifacts subdirectory in the GCS bucket)
  • add jacoco-agent.properties file to classpath (e.g. to resources) with destfile set to a writable directory
  • add external storage read/write permissions to AndroidManifest.xml

Of all the above, do you think it would be feasible to add support for --environment-variables and --directories-to-pull (in some generic way, perhaps verbatim strings) gcloud options to the plugin, and most importantly, an ability to copyArtifact the artifacts subdirectory?

Plugin with id 'firebase-test-lab' not found.

Hi
I try o run a firebase test.
I add in my build.gradle file
repositories {
jcenter()
google()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://plugins.gradle.org/m2/" }
}
and
dependencies {
classpath "gradle.plugin.ru.gildor.gradle.firebase.testlab:firebase-test-lab:0.1.1"
}

in my app/build.gradle file I add
apply plugin: 'firebase-test-lab'
and the firebaseTestLab {..}
gradlew tasks run in to this error
What went wrong:
A problem occurred evaluating project ':app'.
Plugin with id 'firebase-test-lab' not found.

Did I miss any part ?
Rregards

Is it alive?

Hey, it is a nice start! Are you going to continue?

What's the plugin's repository?

> Could not resolve all files for configuration ':classpath'.
   > Could not find any matches for ru.gildor.gradle.firebase.testlab:firebase-test-lab:+ as no versions of ru.gildor.gradle.firebase.testlab:firebase-test-lab are available.
     Searched in the following locations:
         https://jcenter.bintray.com/ru/gildor/gradle/firebase/testlab/firebase-test-lab/maven-metadata.xml
         https://jcenter.bintray.com/ru/gildor/gradle/firebase/testlab/firebase-test-lab/
         https://repo1.maven.org/maven2/ru/gildor/gradle/firebase/testlab/firebase-test-lab/maven-metadata.xml
         https://repo1.maven.org/maven2/ru/gildor/gradle/firebase/testlab/firebase-test-lab/
         https://maven.fabric.io/public/ru/gildor/gradle/firebase/testlab/firebase-test-lab/maven-metadata.xml
         https://maven.fabric.io/public/ru/gildor/gradle/firebase/testlab/firebase-test-lab/
         https://plugins.gradle.org/m2/ru/gildor/gradle/firebase/testlab/firebase-test-lab/maven-metadata.xml
         https://plugins.gradle.org/m2/ru/gildor/gradle/firebase/testlab/firebase-test-lab/

can't find it

API change in variant output

The android gradle plugin 3.0.0 broke the variant output api, thus the plugin does not work with the following error:

Unable to find method 'com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;'. Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

It's necessary to find another way to get the APK paths.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.