buildSrc/src/main/kotlin/AndroidTests.kt
author Da Risk <da_risk@geekorum.com>
Wed, 03 Jan 2024 15:26:40 -0400
changeset 1174 731f6ee517b6
parent 1158 20cd659d4fbf
child 1199 a46073d44b35
permissions -rw-r--r--
update license headers
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
 *
1174
731f6ee517b6 update license headers
Da Risk <da_risk@geekorum.com>
parents: 1158
diff changeset
     4
 * Copyright (C) 2017-2024 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
1013
18d820f292d6 build: rework buildSrc to use agp-api
Da Risk <da_risk@geekorum.com>
parents: 1010
diff changeset
    23
import com.android.build.api.dsl.CommonExtension
1138
dcfb7a58a4d9 build: update to jvm toolchain 17
Da Risk <da_risk@geekorum.com>
parents: 1081
diff changeset
    24
import com.android.build.api.dsl.DefaultConfig
0
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
357
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
    27
import org.gradle.api.artifacts.DependencyConstraint
201
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    28
import org.gradle.api.artifacts.ExternalModuleDependency
357
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
    29
import org.gradle.api.artifacts.dsl.DependencyConstraintHandler
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    30
import org.gradle.api.artifacts.dsl.DependencyHandler
1013
18d820f292d6 build: rework buildSrc to use agp-api
Da Risk <da_risk@geekorum.com>
parents: 1010
diff changeset
    31
import org.gradle.kotlin.dsl.*
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    32
935
ec942dc5c721 build: update test dependencies
Da Risk <da_risk@geekorum.com>
parents: 918
diff changeset
    33
const val espressoVersion = "3.5.1"
ec942dc5c721 build: update test dependencies
Da Risk <da_risk@geekorum.com>
parents: 918
diff changeset
    34
const val androidxTestRunnerVersion = "1.5.2"
ec942dc5c721 build: update test dependencies
Da Risk <da_risk@geekorum.com>
parents: 918
diff changeset
    35
const val androidxTestCoreVersion = "1.5.0"
1158
20cd659d4fbf build: update a few test dependencies
Da Risk <da_risk@geekorum.com>
parents: 1138
diff changeset
    36
const val robolectricVersion = "4.11.1"
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    37
1138
dcfb7a58a4d9 build: update to jvm toolchain 17
Da Risk <da_risk@geekorum.com>
parents: 1081
diff changeset
    38
private typealias BaseExtension = CommonExtension<*, *, DefaultConfig, *, *>
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    39
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
 * Configuration for espresso and robolectric usage in an Android project
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
internal fun Project.configureTests() {
1138
dcfb7a58a4d9 build: update to jvm toolchain 17
Da Risk <da_risk@geekorum.com>
parents: 1081
diff changeset
    44
    extensions.configure<BaseExtension>("android") {
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    45
        defaultConfig {
726
a89436120a6d Make SendTransactionsWorkerTest work with hilt
Da Risk <da_risk@geekorum.com>
parents: 644
diff changeset
    46
            testInstrumentationRunner = "com.geekorum.ttrss.HiltRunner"
840
b41d8bc8870e build: update various dependencies
Da Risk <da_risk@geekorum.com>
parents: 833
diff changeset
    47
            testInstrumentationRunnerArguments += mapOf(
b41d8bc8870e build: update various dependencies
Da Risk <da_risk@geekorum.com>
parents: 833
diff changeset
    48
                "clearPackageData" to "true",
b41d8bc8870e build: update various dependencies
Da Risk <da_risk@geekorum.com>
parents: 833
diff changeset
    49
                "disableAnalytics" to "true"
b41d8bc8870e build: update various dependencies
Da Risk <da_risk@geekorum.com>
parents: 833
diff changeset
    50
            )
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    51
        }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    52
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    53
        testOptions {
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    54
            execution = "ANDROIDX_TEST_ORCHESTRATOR"
128
e48c1ddb578f Disable animation during instrumentation tests
Da Risk <da_risk@geekorum.com>
parents: 64
diff changeset
    55
            animationsDisabled = true
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    56
1010
85e3a2f4f1cf build: update to AGP 8.0
Da Risk <da_risk@geekorum.com>
parents: 943
diff changeset
    57
            unitTests {
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    58
                isIncludeAndroidResources = true
1010
85e3a2f4f1cf build: update to AGP 8.0
Da Risk <da_risk@geekorum.com>
parents: 943
diff changeset
    59
            }
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    60
        }
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
    dependencies {
397
3881abcdd84c Update to kotlin-1.3.50
Da Risk <da_risk@geekorum.com>
parents: 357
diff changeset
    64
        dualTestImplementation(kotlin("test-junit"))
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    65
935
ec942dc5c721 build: update test dependencies
Da Risk <da_risk@geekorum.com>
parents: 918
diff changeset
    66
        androidTestUtil("androidx.test:orchestrator:1.4.2")
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    67
        androidTestImplementation("androidx.test:runner:$androidxTestRunnerVersion")
935
ec942dc5c721 build: update test dependencies
Da Risk <da_risk@geekorum.com>
parents: 918
diff changeset
    68
        dualTestImplementation("androidx.test.ext:junit-ktx:1.1.5")
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    69
64
0b7cf61c75e5 buildSrc: AndroidTests update dependencies version
Da Risk <da_risk@geekorum.com>
parents: 19
diff changeset
    70
        dualTestImplementation("androidx.test:core-ktx:$androidxTestCoreVersion")
935
ec942dc5c721 build: update test dependencies
Da Risk <da_risk@geekorum.com>
parents: 918
diff changeset
    71
        dualTestImplementation("androidx.test:rules:1.5.0")
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    72
357
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
    73
        // fragment testing is usually declared on debugImplementation configuration and need these dependencies
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
    74
        constraints {
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
    75
            debugImplementation("androidx.test:core:$androidxTestCoreVersion")
935
ec942dc5c721 build: update test dependencies
Da Risk <da_risk@geekorum.com>
parents: 918
diff changeset
    76
            debugImplementation("androidx.test:monitor:1.6.1")
357
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
    77
        }
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
    78
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    79
        dualTestImplementation("androidx.test.espresso:espresso-core:$espressoVersion")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    80
        dualTestImplementation("androidx.test.espresso:espresso-contrib:$espressoVersion")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    81
        dualTestImplementation("androidx.test.espresso:espresso-intents:$espressoVersion")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    82
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    83
        // assertions
935
ec942dc5c721 build: update test dependencies
Da Risk <da_risk@geekorum.com>
parents: 918
diff changeset
    84
        dualTestImplementation("com.google.truth:truth:1.1.3")
ec942dc5c721 build: update test dependencies
Da Risk <da_risk@geekorum.com>
parents: 918
diff changeset
    85
        dualTestImplementation("androidx.test.ext:truth:1.5.0")
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    86
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    87
        // mock
1158
20cd659d4fbf build: update a few test dependencies
Da Risk <da_risk@geekorum.com>
parents: 1138
diff changeset
    88
        testImplementation("io.mockk:mockk:1.13.8")
20cd659d4fbf build: update a few test dependencies
Da Risk <da_risk@geekorum.com>
parents: 1138
diff changeset
    89
        androidTestImplementation("io.mockk:mockk-android:1.13.8")
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    90
        testImplementation("org.robolectric:robolectric:$robolectricVersion")
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    91
635
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
    92
        constraints {
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
    93
            dualTestImplementation(kotlin("reflect")) {
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
    94
                because("Use the kotlin version that we use")
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
    95
            }
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
    96
            androidTestImplementation("org.objenesis:objenesis") {
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
    97
                because("3.x version use instructions only available with minSdk 26 (Android O)")
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
    98
                version {
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
    99
                    strictly("2.6")
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
   100
                }
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
   101
            }
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
   102
        }
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   103
    }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   104
}
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   105
19
5dcfa95ec99b buildscript: expose dualTestImplementation method
Da Risk <da_risk@geekorum.com>
parents: 0
diff changeset
   106
fun DependencyHandler.dualTestImplementation(dependencyNotation: Any) {
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   107
    add("androidTestImplementation", dependencyNotation)
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   108
    add("testImplementation", 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
201
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   111
fun DependencyHandler.dualTestImplementation(dependencyNotation: Any, action: ExternalModuleDependency.() -> Unit) {
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   112
    val closure = closureOf(action)
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   113
    add("androidTestImplementation", dependencyNotation, closure)
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   114
    add("testImplementation", dependencyNotation, closure)
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   115
}
f89d3c622b33 tests: Update espresso and truth
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
   116
357
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
   117
internal fun DependencyHandler.androidTestImplementation(dependencyNotation: Any): Dependency? =
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   118
    add("androidTestImplementation", dependencyNotation)
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   119
635
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
   120
internal fun DependencyHandler.androidTestImplementation(dependencyNotation: Any, action: ExternalModuleDependency.() -> Unit) {
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
   121
    val closure = closureOf(action)
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
   122
    add("androidTestImplementation", dependencyNotation, closure)
1c1d190b326a build: update to agp 4.0.0-beta1 and latest play-publisher plugin
Da Risk <da_risk@geekorum.com>
parents: 611
diff changeset
   123
}
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   124
357
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
   125
internal fun DependencyHandler.androidTestUtil(dependencyNotation: Any): Dependency? =
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   126
    add("androidTestUtil", dependencyNotation)
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   127
357
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
   128
internal fun DependencyHandler.testImplementation(dependencyNotation: Any): Dependency? =
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   129
    add("testImplementation", dependencyNotation)
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
   130
357
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
   131
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
   132
internal fun DependencyConstraintHandler.debugImplementation(dependencyConstraintNotation: Any): DependencyConstraint? =
da0a1c954222 tests: update to Truth-1.0
Da Risk <da_risk@geekorum.com>
parents: 328
diff changeset
   133
    add("debugImplementation", dependencyConstraintNotation)