| author | Da Risk <da_risk@geekorum.com> |
| Mon, 17 Feb 2025 19:26:15 -0400 | |
| changeset 82 | e9e1adc862c0 |
| 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 |
||
| 19 | 24 |
import com.android.build.api.dsl.CommonExtension |
25 |
import com.android.build.api.dsl.DefaultConfig |
|
| 1 | 26 |
import com.android.build.gradle.BaseExtension |
27 |
import com.android.build.gradle.internal.dsl.TestOptions |
|
28 |
import org.gradle.api.Project |
|
29 |
import org.gradle.api.artifacts.Dependency |
|
30 |
import org.gradle.api.artifacts.DependencyConstraint |
|
31 |
import org.gradle.api.artifacts.ExternalModuleDependency |
|
32 |
import org.gradle.api.artifacts.dsl.DependencyConstraintHandler |
|
33 |
import org.gradle.api.artifacts.dsl.DependencyHandler |
|
|
46
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
34 |
import org.gradle.kotlin.dsl.* |
| 1 | 35 |
|
|
46
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
36 |
const val espressoVersion = "3.5.1" |
|
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
37 |
const val androidxTestRunnerVersion = "1.5.2" |
|
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
38 |
const val androidxTestCoreVersion = "1.5.0" |
|
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
39 |
const val robolectricVersion = "4.10.2" |
| 1 | 40 |
|
| 72 | 41 |
private typealias BaseExtension = CommonExtension<*, *, DefaultConfig, *, *, *> |
| 1 | 42 |
|
43 |
/* |
|
44 |
* Configuration for espresso and robolectric usage in an Android project |
|
45 |
*/ |
|
| 19 | 46 |
@Suppress("UnstableApiUsage")
|
| 1 | 47 |
internal fun Project.configureTests() {
|
| 19 | 48 |
extensions.configure<BaseExtension>("android") {
|
| 1 | 49 |
defaultConfig {
|
50 |
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" |
|
|
18
3ccb29f83309
build: update to robolectric 4.6.1
Da Risk <da_risk@geekorum.com>
parents:
10
diff
changeset
|
51 |
testInstrumentationRunnerArguments += mapOf( |
|
3ccb29f83309
build: update to robolectric 4.6.1
Da Risk <da_risk@geekorum.com>
parents:
10
diff
changeset
|
52 |
"clearPackageData" to "true", |
|
3ccb29f83309
build: update to robolectric 4.6.1
Da Risk <da_risk@geekorum.com>
parents:
10
diff
changeset
|
53 |
"disableAnalytics" to "true" |
|
3ccb29f83309
build: update to robolectric 4.6.1
Da Risk <da_risk@geekorum.com>
parents:
10
diff
changeset
|
54 |
) |
| 1 | 55 |
} |
56 |
||
57 |
testOptions {
|
|
58 |
execution = "ANDROIDX_TEST_ORCHESTRATOR" |
|
59 |
animationsDisabled = true |
|
60 |
||
| 19 | 61 |
unitTests {
|
| 1 | 62 |
isIncludeAndroidResources = true |
| 19 | 63 |
} |
| 1 | 64 |
} |
65 |
} |
|
66 |
||
67 |
||
68 |
dependencies {
|
|
69 |
dualTestImplementation(kotlin("test-junit"))
|
|
70 |
||
|
46
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
71 |
androidTestUtil("androidx.test:orchestrator:1.4.2")
|
| 1 | 72 |
androidTestImplementation("androidx.test:runner:$androidxTestRunnerVersion")
|
73 |
dualTestImplementation("androidx.test.ext:junit-ktx:1.1.1")
|
|
74 |
||
75 |
dualTestImplementation("androidx.test:core-ktx:$androidxTestCoreVersion")
|
|
|
46
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
76 |
dualTestImplementation("androidx.test:rules:1.5.0")
|
| 1 | 77 |
// fragment testing is usually declared on debugImplementation configuration and need these dependencies |
78 |
constraints {
|
|
79 |
debugImplementation("androidx.test:core:$androidxTestCoreVersion")
|
|
80 |
debugImplementation("androidx.test:monitor:$androidxTestRunnerVersion")
|
|
81 |
} |
|
82 |
||
83 |
dualTestImplementation("androidx.test.espresso:espresso-core:$espressoVersion")
|
|
|
46
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
84 |
dualTestImplementation("androidx.test.espresso:espresso-contrib:$espressoVersion") {
|
|
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
85 |
exclude("com.google.protobuf", "protobuf-lite")
|
|
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
86 |
} |
| 1 | 87 |
dualTestImplementation("androidx.test.espresso:espresso-intents:$espressoVersion")
|
88 |
||
89 |
// assertions |
|
90 |
dualTestImplementation("com.google.truth:truth:1.0")
|
|
91 |
dualTestImplementation("androidx.test.ext:truth:1.3.0-alpha01")
|
|
92 |
||
93 |
// mock |
|
|
46
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
94 |
testImplementation("io.mockk:mockk:1.13.5")
|
|
3eec74c864bf
geekdroid: update dependencies
Da Risk <da_risk@geekorum.com>
parents:
37
diff
changeset
|
95 |
androidTestImplementation("io.mockk:mockk-android:1.13.5")
|
| 1 | 96 |
testImplementation("org.robolectric:robolectric:$robolectricVersion")
|
97 |
||
98 |
constraints {
|
|
99 |
dualTestImplementation(kotlin("reflect")) {
|
|
100 |
because("Use the kotlin version that we use")
|
|
101 |
} |
|
102 |
androidTestImplementation("org.objenesis:objenesis") {
|
|
103 |
because("3.x version use instructions only available with minSdk 26 (Android O)")
|
|
104 |
version {
|
|
105 |
strictly("2.6")
|
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
fun DependencyHandler.dualTestImplementation(dependencyNotation: Any) {
|
|
113 |
add("androidTestImplementation", dependencyNotation)
|
|
114 |
add("testImplementation", dependencyNotation)
|
|
115 |
} |
|
116 |
||
117 |
fun DependencyHandler.dualTestImplementation(dependencyNotation: Any, action: ExternalModuleDependency.() -> Unit) {
|
|
118 |
val closure = closureOf(action) |
|
119 |
add("androidTestImplementation", dependencyNotation, closure)
|
|
120 |
add("testImplementation", dependencyNotation, closure)
|
|
121 |
} |
|
122 |
||
123 |
internal fun DependencyHandler.androidTestImplementation(dependencyNotation: Any): Dependency? = |
|
124 |
add("androidTestImplementation", dependencyNotation)
|
|
125 |
||
126 |
internal fun DependencyHandler.androidTestImplementation(dependencyNotation: Any, action: ExternalModuleDependency.() -> Unit) {
|
|
127 |
val closure = closureOf(action) |
|
128 |
add("androidTestImplementation", dependencyNotation, closure)
|
|
129 |
} |
|
130 |
||
131 |
internal fun DependencyHandler.androidTestUtil(dependencyNotation: Any): Dependency? = |
|
132 |
add("androidTestUtil", dependencyNotation)
|
|
133 |
||
134 |
internal fun DependencyHandler.testImplementation(dependencyNotation: Any): Dependency? = |
|
135 |
add("testImplementation", dependencyNotation)
|
|
136 |
||
137 |
internal fun DependencyConstraintHandler.debugImplementation(dependencyConstraintNotation: Any): DependencyConstraint? = |
|
138 |
add("debugImplementation", dependencyConstraintNotation)
|