buildSrc/src/main/kotlin/AndroidTests.kt
author Da Risk <da_risk@geekorum.com>
Fri, 14 Jun 2019 18:37:04 -0700
changeset 256 64383b6d394c
parent 203 e7edb332d468
child 294 cf42669347cf
permissions -rw-r--r--
PurgeArticlesWorker: add tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
137
5464f07a306c Update copyright headers for 2019
Da Risk <da_risk@geekorum.com>
parents: 128
diff changeset
     1
/*
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     2
 * Geekttrss is a RSS feed reader application on the Android Platform.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     3
 *
137
5464f07a306c Update copyright headers for 2019
Da Risk <da_risk@geekorum.com>
parents: 128
diff changeset
     4
 * Copyright (C) 2017-2019 by Frederic-Charles Barthelery.
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     5
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     6
 * This file is part of Geekttrss.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     7
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     8
 * Geekttrss is free software: you can redistribute it and/or modify
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     9
 * it under the terms of the GNU General Public License as published by
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    10
 * the Free Software Foundation, either version 3 of the License, or
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    11
 * (at your option) any later version.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    12
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    13
 * Geekttrss is distributed in the hope that it will be useful,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    16
 * GNU General Public License for more details.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    17
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    18
 * You should have received a copy of the GNU General Public License
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    19
 * along with Geekttrss.  If not, see <http://www.gnu.org/licenses/>.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    20
 */
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    21
package com.geekorum.build
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    22
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    23
import com.android.build.gradle.BaseExtension
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    24
import com.android.build.gradle.internal.dsl.TestOptions
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    25
import org.gradle.api.Project
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    26
import org.gradle.api.artifacts.Dependency
201
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    27
import org.gradle.api.artifacts.ExternalModuleDependency
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    28
import org.gradle.api.artifacts.dsl.DependencyHandler
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    29
import org.gradle.kotlin.dsl.closureOf
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    30
import org.gradle.kotlin.dsl.dependencies
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    31
import org.gradle.kotlin.dsl.extra
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    32
import org.gradle.kotlin.dsl.kotlin
203
e7edb332d468 build: fix missing importj
Da Risk <da_risk@geekorum.com>
parents: 201
diff changeset
    33
import org.gradle.kotlin.dsl.provideDelegate
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    34
201
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    35
const val espressoVersion = "3.2.0"
64
0b7cf61c75e5 buildSrc: AndroidTests update dependencies version
Da Risk <da_risk@geekorum.com>
parents: 19
diff changeset
    36
const val androidxTestRunnerVersion = "1.1.1"
0b7cf61c75e5 buildSrc: AndroidTests update dependencies version
Da Risk <da_risk@geekorum.com>
parents: 19
diff changeset
    37
const val androidxTestCoreVersion = "1.1.0"
0b7cf61c75e5 buildSrc: AndroidTests update dependencies version
Da Risk <da_risk@geekorum.com>
parents: 19
diff changeset
    38
const val androidxTestExtVersion = "1.1.0"
0b7cf61c75e5 buildSrc: AndroidTests update dependencies version
Da Risk <da_risk@geekorum.com>
parents: 19
diff changeset
    39
const val robolectricVersion = "4.1"
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    40
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    41
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    42
/*
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    43
 * Configuration for espresso and robolectric usage in an Android project
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    44
 */
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    45
internal fun Project.configureTests() {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    46
    val kotlinVersion: String by rootProject.extra
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    47
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    48
    extensions.configure<BaseExtension>("android") {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    49
        defaultConfig {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    50
            testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
64
0b7cf61c75e5 buildSrc: AndroidTests update dependencies version
Da Risk <da_risk@geekorum.com>
parents: 19
diff changeset
    51
            testInstrumentationRunnerArgument("clearPackageData", "true")
256
64383b6d394c PurgeArticlesWorker: add tests
Da Risk <da_risk@geekorum.com>
parents: 203
diff changeset
    52
            testInstrumentationRunnerArgument("disableAnalytics", "true")
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    53
        }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    54
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    55
        testOptions {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    56
            execution = "ANDROIDX_TEST_ORCHESTRATOR"
128
e48c1ddb578f Disable animation during instrumentation tests
Da Risk <da_risk@geekorum.com>
parents: 64
diff changeset
    57
            animationsDisabled = true
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    58
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    59
            unitTests(closureOf<TestOptions.UnitTestOptions> {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    60
                isIncludeAndroidResources = true
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    61
            })
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    62
        }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    63
    }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    64
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    65
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    66
    dependencies {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    67
        dualTestImplementation(kotlin("test-junit", kotlinVersion))
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    68
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    69
        androidTestUtil("androidx.test:orchestrator:$androidxTestRunnerVersion")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    70
        androidTestImplementation("androidx.test:runner:$androidxTestRunnerVersion")
64
0b7cf61c75e5 buildSrc: AndroidTests update dependencies version
Da Risk <da_risk@geekorum.com>
parents: 19
diff changeset
    71
        dualTestImplementation("androidx.test.ext:junit-ktx:$androidxTestExtVersion")
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    72
64
0b7cf61c75e5 buildSrc: AndroidTests update dependencies version
Da Risk <da_risk@geekorum.com>
parents: 19
diff changeset
    73
        dualTestImplementation("androidx.test:core-ktx:$androidxTestCoreVersion")
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    74
        dualTestImplementation("androidx.test:rules:$androidxTestRunnerVersion")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    75
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    76
        dualTestImplementation("androidx.test.espresso:espresso-core:$espressoVersion")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    77
        dualTestImplementation("androidx.test.espresso:espresso-contrib:$espressoVersion")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    78
        dualTestImplementation("androidx.test.espresso:espresso-intents:$espressoVersion")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    79
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    80
        // assertions
201
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    81
        dualTestImplementation("com.google.truth:truth:0.44")
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    82
        dualTestImplementation("androidx.test.ext:truth:$androidxTestExtVersion")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    83
201
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    84
        // fix for guava listenablefuture conflict with application runtime version
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    85
        dualTestImplementation("com.google.guava:listenablefuture:1.0") {
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    86
            isForce = true
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    87
        }
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    88
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    89
        // mock
64
0b7cf61c75e5 buildSrc: AndroidTests update dependencies version
Da Risk <da_risk@geekorum.com>
parents: 19
diff changeset
    90
        testImplementation("io.mockk:mockk:1.9")
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    91
        testImplementation("org.robolectric:robolectric:$robolectricVersion")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    92
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    93
    }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    94
}
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    95
19
5dcfa95ec99b buildscript: expose dualTestImplementation method
Da Risk <da_risk@geekorum.com>
parents: 0
diff changeset
    96
fun DependencyHandler.dualTestImplementation(dependencyNotation: Any) {
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    97
    add("androidTestImplementation", dependencyNotation)
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    98
    add("testImplementation", dependencyNotation)
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    99
}
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   100
201
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   101
fun DependencyHandler.dualTestImplementation(dependencyNotation: Any, action: ExternalModuleDependency.() -> Unit) {
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   102
    val closure = closureOf(action)
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   103
    add("androidTestImplementation", dependencyNotation, closure)
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   104
    add("testImplementation", dependencyNotation, closure)
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   105
}
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   106
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   107
internal fun DependencyHandler.`androidTestImplementation`(dependencyNotation: Any): Dependency? =
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   108
    add("androidTestImplementation", dependencyNotation)
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   109
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   110
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   111
internal fun DependencyHandler.`androidTestUtil`(dependencyNotation: Any): Dependency? =
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   112
    add("androidTestUtil", dependencyNotation)
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   113
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   114
internal fun DependencyHandler.`testImplementation`(dependencyNotation: Any): Dependency? =
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   115
    add("testImplementation", dependencyNotation)
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   116