Skip to content

Instantly share code, notes, and snippets.

@loeschg
Last active August 29, 2015 14:07
Show Gist options
  • Save loeschg/3ce24c34dec364270ab8 to your computer and use it in GitHub Desktop.
Save loeschg/3ce24c34dec364270ab8 to your computer and use it in GitHub Desktop.

Revisions

  1. loeschg revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion build.gradle
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ def excludeEspressoFilesIfNecessary(theTask) {

    // Exclude espresso and add the task as a dependency.
    project.task(cleanupTaskName) << {
    FileTree tree = fileTree(dir: TEST_SRC_DIR)
    def FileTree tree = fileTree(dir: TEST_SRC_DIR)
    tree.exclude TO_EXCLUDE
    theTask.source = tree
    }
  2. loeschg revised this gist Oct 7, 2014. 1 changed file with 10 additions and 5 deletions.
    15 changes: 10 additions & 5 deletions build.gradle
    Original file line number Diff line number Diff line change
    @@ -13,17 +13,22 @@ tasks.whenTaskAdded { theTask ->
    * Android Testing. (╯°□°)╯︵ ┻━┻
    */
    def excludeEspressoFilesIfNecessary(theTask) {
    def compileTestPattern= /compileTest([^ ]*)Java/

    // Modify these if needed.
    def final TEST_SRC_DIR = 'src/test/java'
    def final TO_EXCLUDE = '**/espresso/**/*.java'

    def final compileTestPattern= /compileTest([^ ]*)Java/
    if (theTask.name.matches(compileTestPattern)) { // find all task names.

    // Grabs the name of the variant to use when naming the new task.
    def matcher = (theTask.name =~ compileTestPattern)
    def cleanupTaskName = "touchUp${matcher[0][1]}RobolectricSourceSet"

    // Exclude espresso and add the task as a dependency.
    project.task(cleanupTaskName) << {
    FileTree tree = fileTree(dir: 'src/test/java')
    tree.exclude '**/espresso/**/*.java'
    FileTree tree = fileTree(dir: TEST_SRC_DIR)
    tree.exclude TO_EXCLUDE
    theTask.source = tree
    }
    theTask.dependsOn(cleanupTaskName)
  3. loeschg revised this gist Oct 7, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions build.gradle
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    /** Hook into existing tasks. */
    tasks.whenTaskAdded { theTask ->
    checkAndExcludeEspressoFilesFromTask(theTask)
    excludeEspressoFilesIfNecessary(theTask)
    }

    /**
    @@ -12,7 +12,7 @@ tasks.whenTaskAdded { theTask ->
    *
    * Android Testing. (╯°□°)╯︵ ┻━┻
    */
    def checkAndExcludeEspressoFilesFromTask(theTask) {
    def excludeEspressoFilesIfNecessary(theTask) {
    def compileTestPattern= /compileTest([^ ]*)Java/
    if (theTask.name.matches(compileTestPattern)) { // find all task names.

  4. loeschg revised this gist Oct 7, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions build.gradle
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    /** Hook into existing tasks. */
    tasks.whenTaskAdded { theTask ->
    excludeEspressoFilesFromTask(theTask)
    checkAndExcludeEspressoFilesFromTask(theTask)
    }

    /**
    @@ -12,7 +12,7 @@ tasks.whenTaskAdded { theTask ->
    *
    * Android Testing. (╯°□°)╯︵ ┻━┻
    */
    def excludeEspressoFilesFromTask(theTask) {
    def checkAndExcludeEspressoFilesFromTask(theTask) {
    def compileTestPattern= /compileTest([^ ]*)Java/
    if (theTask.name.matches(compileTestPattern)) { // find all task names.

  5. loeschg revised this gist Oct 7, 2014. No changes.
  6. loeschg revised this gist Oct 7, 2014. No changes.
  7. loeschg revised this gist Oct 7, 2014. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions build.gradle
    Original file line number Diff line number Diff line change
    @@ -10,15 +10,17 @@ tasks.whenTaskAdded { theTask ->
    * normally unless doing this. Double-espresso is used to fix a conflicting Dagger 1.2 dependency
    * with Espresso.
    *
    * Android Testing. It's a mess. (╯°□°)╯︵ ┻━┻
    * Android Testing. (╯°□°)╯︵ ┻━┻
    */
    def excludeEspressoFilesFromTask(theTask) {
    def tasks = ['compileTestStagingDebugJava', 'compileTestProdDebugJava']
    if (tasks.contains(theTask.name.toString())) {

    def variantPattern = /compileTest(.*)Java/
    def matcher = (theTask.name =~ variantPattern)
    def compileTestPattern= /compileTest([^ ]*)Java/
    if (theTask.name.matches(compileTestPattern)) { // find all task names.
    // Grabs the name of the variant to use when naming the new task.
    def matcher = (theTask.name =~ compileTestPattern)
    def cleanupTaskName = "touchUp${matcher[0][1]}RobolectricSourceSet"

    // Exclude espresso and add the task as a dependency.
    project.task(cleanupTaskName) << {
    FileTree tree = fileTree(dir: 'src/test/java')
    tree.exclude '**/espresso/**/*.java'
  8. loeschg created this gist Oct 7, 2014.
    29 changes: 29 additions & 0 deletions build.gradle
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    /** Hook into existing tasks. */
    tasks.whenTaskAdded { theTask ->
    excludeEspressoFilesFromTask(theTask)
    }

    /**
    * This excludes Espresso tests from Robolectric. http://stackoverflow.com/a/24706452/413254
    *
    * This was needed when using double-espresso. I couldn't get Robolectric to exclude them
    * normally unless doing this. Double-espresso is used to fix a conflicting Dagger 1.2 dependency
    * with Espresso.
    *
    * Android Testing. It's a mess. (╯°□°)╯︵ ┻━┻
    */
    def excludeEspressoFilesFromTask(theTask) {
    def tasks = ['compileTestStagingDebugJava', 'compileTestProdDebugJava']
    if (tasks.contains(theTask.name.toString())) {

    def variantPattern = /compileTest(.*)Java/
    def matcher = (theTask.name =~ variantPattern)
    def cleanupTaskName = "touchUp${matcher[0][1]}RobolectricSourceSet"
    project.task(cleanupTaskName) << {
    FileTree tree = fileTree(dir: 'src/test/java')
    tree.exclude '**/espresso/**/*.java'
    theTask.source = tree
    }
    theTask.dependsOn(cleanupTaskName)
    }
    }