| author | Da Risk <da_risk@geekorum.com> |
| Mon, 09 Mar 2026 16:20:21 -0400 | |
| changeset 100 | 9ec927c219b0 |
| parent 75 | 534a19e25217 |
| permissions | -rw-r--r-- |
| 10 | 1 |
/* |
2 |
* Geekdroid is a utility library for development on the Android |
|
3 |
* Platform. |
|
4 |
* |
|
|
75
534a19e25217
build: update license headers
Da Risk <da_risk@geekorum.com>
parents:
72
diff
changeset
|
5 |
* Copyright (C) 2017-2025 by Frederic-Charles Barthelery. |
| 10 | 6 |
* |
7 |
* This file is part of Geekdroid. |
|
8 |
* |
|
9 |
* Geekdroid is free software: you can redistribute it and/or modify |
|
10 |
* it under the terms of the GNU General Public License as published by |
|
11 |
* the Free Software Foundation, either version 3 of the License, or |
|
12 |
* (at your option) any later version. |
|
13 |
* |
|
14 |
* Geekdroid is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with Geekdroid. If not, see <http://www.gnu.org/licenses/>. |
|
21 |
*/ |
|
| 1 | 22 |
package com.geekorum.build |
23 |
||
| 100 | 24 |
import com.android.build.api.dsl.ApplicationExtension |
| 19 | 25 |
import com.android.build.api.dsl.CommonExtension |
| 100 | 26 |
import com.android.build.api.dsl.LibraryExtension |
| 1 | 27 |
import org.gradle.api.Project |
28 |
import org.gradle.api.artifacts.Dependency |
|
29 |
import org.gradle.api.artifacts.DependencyConstraint |
|
30 |
import org.gradle.api.artifacts.ExternalModuleDependency |
|
31 |
import org.gradle.api.artifacts.dsl.DependencyConstraintHandler |
|
32 |
import org.gradle.api.artifacts.dsl.DependencyHandler |
|
|
46
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
33 |
import org.gradle.kotlin.dsl.* |
| 1 | 34 |
|
| 100 | 35 |
const val espressoVersion = "3.6.1" |
36 |
const val androidxTestRunnerVersion = "1.6.2" |
|
37 |
const val androidxTestCoreVersion = "1.6.1" |
|
38 |
const val robolectricVersion = "4.14.1" |
|
| 1 | 39 |
|
40 |
||
41 |
/* |
|
42 |
* Configuration for espresso and robolectric usage in an Android project |
|
43 |
*/ |
|
44 |
internal fun Project.configureTests() {
|
|
| 100 | 45 |
extensions.configure<CommonExtension>("android") {
|
46 |
if (this is ApplicationExtension) {
|
|
47 |
defaultConfig {
|
|
| 1 | 48 |
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" |
| 100 | 49 |
testInstrumentationRunnerArguments += mapOf( |
50 |
"clearPackageData" to "true", |
|
51 |
"disableAnalytics" to "true" |
|
52 |
) |
|
53 |
} |
|
54 |
} |
|
55 |
if (this is LibraryExtension) {
|
|
56 |
defaultConfig {
|
|
57 |
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" |
|
58 |
testInstrumentationRunnerArguments += mapOf( |
|
59 |
"clearPackageData" to "true", |
|
60 |
"disableAnalytics" to "true" |
|
61 |
) |
|
62 |
} |
|
| 1 | 63 |
} |
64 |
||
| 100 | 65 |
testOptions.apply {
|
| 1 | 66 |
execution = "ANDROIDX_TEST_ORCHESTRATOR" |
67 |
animationsDisabled = true |
|
68 |
||
| 19 | 69 |
unitTests {
|
| 1 | 70 |
isIncludeAndroidResources = true |
| 19 | 71 |
} |
| 1 | 72 |
} |
73 |
} |
|
74 |
||
75 |
dependencies {
|
|
76 |
dualTestImplementation(kotlin("test-junit"))
|
|
77 |
||
| 100 | 78 |
androidTestUtil("androidx.test:orchestrator:1.5.1")
|
| 1 | 79 |
androidTestImplementation("androidx.test:runner:$androidxTestRunnerVersion")
|
| 100 | 80 |
dualTestImplementation("androidx.test.ext:junit-ktx:1.2.1")
|
| 1 | 81 |
|
82 |
dualTestImplementation("androidx.test:core-ktx:$androidxTestCoreVersion")
|
|
| 100 | 83 |
dualTestImplementation("androidx.test:rules:1.6.1")
|
84 |
||
| 1 | 85 |
// fragment testing is usually declared on debugImplementation configuration and need these dependencies |
86 |
constraints {
|
|
87 |
debugImplementation("androidx.test:core:$androidxTestCoreVersion")
|
|
| 100 | 88 |
debugImplementation("androidx.test:monitor:1.7.2")
|
| 1 | 89 |
} |
90 |
||
91 |
dualTestImplementation("androidx.test.espresso:espresso-core:$espressoVersion")
|
|
|
46
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
92 |
dualTestImplementation("androidx.test.espresso:espresso-contrib:$espressoVersion") {
|
|
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
93 |
exclude("com.google.protobuf", "protobuf-lite")
|
|
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
94 |
} |
| 1 | 95 |
dualTestImplementation("androidx.test.espresso:espresso-intents:$espressoVersion")
|
96 |
||
97 |
// assertions |
|
| 100 | 98 |
dualTestImplementation("com.google.truth:truth:1.4.4")
|
99 |
dualTestImplementation("androidx.test.ext:truth:1.6.0")
|
|
| 1 | 100 |
|
101 |
// mock |
|
| 100 | 102 |
testImplementation("io.mockk:mockk:1.13.8")
|
103 |
androidTestImplementation("io.mockk:mockk-android:1.13.8")
|
|
| 1 | 104 |
testImplementation("org.robolectric:robolectric:$robolectricVersion")
|
105 |
||
106 |
constraints {
|
|
107 |
dualTestImplementation(kotlin("reflect")) {
|
|
108 |
because("Use the kotlin version that we use")
|
|
109 |
} |
|
110 |
androidTestImplementation("org.objenesis:objenesis") {
|
|
111 |
because("3.x version use instructions only available with minSdk 26 (Android O)")
|
|
112 |
version {
|
|
113 |
strictly("2.6")
|
|
114 |
} |
|
115 |
} |
|
116 |
} |
|
117 |
} |
|
118 |
} |
|
119 |
||
120 |
fun DependencyHandler.dualTestImplementation(dependencyNotation: Any) {
|
|
121 |
add("androidTestImplementation", dependencyNotation)
|
|
122 |
add("testImplementation", dependencyNotation)
|
|
123 |
} |
|
124 |
||
125 |
fun DependencyHandler.dualTestImplementation(dependencyNotation: Any, action: ExternalModuleDependency.() -> Unit) {
|
|
126 |
val closure = closureOf(action) |
|
127 |
add("androidTestImplementation", dependencyNotation, closure)
|
|
128 |
add("testImplementation", dependencyNotation, closure)
|
|
129 |
} |
|
130 |
||
131 |
internal fun DependencyHandler.androidTestImplementation(dependencyNotation: Any): Dependency? = |
|
132 |
add("androidTestImplementation", dependencyNotation)
|
|
133 |
||
134 |
internal fun DependencyHandler.androidTestImplementation(dependencyNotation: Any, action: ExternalModuleDependency.() -> Unit) {
|
|
135 |
val closure = closureOf(action) |
|
136 |
add("androidTestImplementation", dependencyNotation, closure)
|
|
137 |
} |
|
138 |
||
139 |
internal fun DependencyHandler.androidTestUtil(dependencyNotation: Any): Dependency? = |
|
140 |
add("androidTestUtil", dependencyNotation)
|
|
141 |
||
142 |
internal fun DependencyHandler.testImplementation(dependencyNotation: Any): Dependency? = |
|
143 |
add("testImplementation", dependencyNotation)
|
|
144 |
||
145 |
internal fun DependencyConstraintHandler.debugImplementation(dependencyConstraintNotation: Any): DependencyConstraint? = |
|
146 |
add("debugImplementation", dependencyConstraintNotation)
|