19 * You should have received a copy of the GNU General Public License |
19 * You should have received a copy of the GNU General Public License |
20 * along with AboutOss. If not, see <http://www.gnu.org/licenses/>. |
20 * along with AboutOss. If not, see <http://www.gnu.org/licenses/>. |
21 */ |
21 */ |
22 package com.geekorum.build |
22 package com.geekorum.build |
23 |
23 |
|
24 import com.android.build.api.dsl.ApplicationExtension |
24 import com.android.build.api.dsl.CommonExtension |
25 import com.android.build.api.dsl.CommonExtension |
25 import com.android.build.api.dsl.DefaultConfig |
26 import com.android.build.api.dsl.DefaultConfig |
|
27 import com.android.build.api.dsl.LibraryExtension |
26 import com.android.build.gradle.BaseExtension |
28 import com.android.build.gradle.BaseExtension |
27 import com.android.build.gradle.internal.dsl.TestOptions |
29 import com.android.build.gradle.internal.dsl.TestOptions |
28 import org.gradle.api.Project |
30 import org.gradle.api.Project |
29 import org.gradle.api.artifacts.Dependency |
31 import org.gradle.api.artifacts.Dependency |
30 import org.gradle.api.artifacts.DependencyConstraint |
32 import org.gradle.api.artifacts.DependencyConstraint |
34 import org.gradle.kotlin.dsl.closureOf |
36 import org.gradle.kotlin.dsl.closureOf |
35 import org.gradle.kotlin.dsl.configure |
37 import org.gradle.kotlin.dsl.configure |
36 import org.gradle.kotlin.dsl.dependencies |
38 import org.gradle.kotlin.dsl.dependencies |
37 import org.gradle.kotlin.dsl.kotlin |
39 import org.gradle.kotlin.dsl.kotlin |
38 |
40 |
39 const val espressoVersion = "3.5.0-alpha07" // alpha for this bug https://github.com/robolectric/robolectric/issues/6593 |
41 const val espressoVersion = "3.6.1" |
40 const val androidxTestRunnerVersion = "1.4.0" |
42 const val androidxTestRunnerVersion = "1.6.2" |
41 const val androidxTestCoreVersion = "1.4.0" |
43 const val androidxTestCoreVersion = "1.6.1" |
42 const val robolectricVersion = "4.8.2" |
44 const val robolectricVersion = "4.14.1" |
43 |
45 |
44 private typealias BaseExtension = CommonExtension<*, *, DefaultConfig, *, *, *> |
|
45 |
46 |
46 /* |
47 /* |
47 * Configuration for espresso and robolectric usage in an Android project |
48 * Configuration for espresso and robolectric usage in an Android project |
48 */ |
49 */ |
49 @Suppress("UnstableApiUsage") |
|
50 internal fun Project.configureTests() { |
50 internal fun Project.configureTests() { |
51 extensions.configure<BaseExtension>("android") { |
51 extensions.configure<CommonExtension>("android") { |
52 defaultConfig { |
52 if (this is ApplicationExtension) { |
53 testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" |
53 defaultConfig { |
54 testInstrumentationRunnerArguments += mapOf( |
54 testInstrumentationRunner = "com.geekorum.ttrss.HiltRunner" |
55 "clearPackageData" to "true", |
55 testInstrumentationRunnerArguments += mapOf( |
56 "disableAnalytics" to "true" |
56 "clearPackageData" to "true", |
57 ) |
57 "disableAnalytics" to "true" |
|
58 ) |
|
59 } |
|
60 } |
|
61 if (this is LibraryExtension) { |
|
62 defaultConfig { |
|
63 testInstrumentationRunner = "com.geekorum.ttrss.HiltRunner" |
|
64 testInstrumentationRunnerArguments += mapOf( |
|
65 "clearPackageData" to "true", |
|
66 "disableAnalytics" to "true" |
|
67 ) |
|
68 } |
58 } |
69 } |
59 |
70 |
60 testOptions { |
71 testOptions.apply { |
61 execution = "ANDROIDX_TEST_ORCHESTRATOR" |
72 execution = "ANDROIDX_TEST_ORCHESTRATOR" |
62 animationsDisabled = true |
73 animationsDisabled = true |
63 |
74 |
64 unitTests { |
75 unitTests { |
65 isIncludeAndroidResources = true |
76 isIncludeAndroidResources = true |
66 } |
77 } |
67 } |
78 } |
68 } |
79 } |
69 |
80 |
70 |
|
71 dependencies { |
81 dependencies { |
72 dualTestImplementation(kotlin("test-junit")) |
82 dualTestImplementation(kotlin("test-junit")) |
73 |
83 |
74 androidTestUtil("androidx.test:orchestrator:$androidxTestRunnerVersion") |
84 androidTestUtil("androidx.test:orchestrator:1.5.1") |
75 androidTestImplementation("androidx.test:runner:$androidxTestRunnerVersion") |
85 androidTestImplementation("androidx.test:runner:$androidxTestRunnerVersion") |
76 dualTestImplementation("androidx.test.ext:junit-ktx:1.1.1") |
86 dualTestImplementation("androidx.test.ext:junit-ktx:1.2.1") |
77 |
87 |
78 dualTestImplementation("androidx.test:core-ktx:$androidxTestCoreVersion") |
88 dualTestImplementation("androidx.test:core-ktx:$androidxTestCoreVersion") |
79 dualTestImplementation("androidx.test:rules:$androidxTestRunnerVersion") |
89 dualTestImplementation("androidx.test:rules:1.6.1") |
|
90 |
80 // fragment testing is usually declared on debugImplementation configuration and need these dependencies |
91 // fragment testing is usually declared on debugImplementation configuration and need these dependencies |
81 constraints { |
92 constraints { |
82 debugImplementation("androidx.test:core:$androidxTestCoreVersion") |
93 debugImplementation("androidx.test:core:$androidxTestCoreVersion") |
83 debugImplementation("androidx.test:monitor:$androidxTestRunnerVersion") |
94 debugImplementation("androidx.test:monitor:1.7.2") |
84 } |
95 } |
85 |
96 |
86 dualTestImplementation("androidx.test.espresso:espresso-core:$espressoVersion") |
97 dualTestImplementation("androidx.test.espresso:espresso-core:$espressoVersion") |
87 dualTestImplementation("androidx.test.espresso:espresso-contrib:$espressoVersion") |
98 dualTestImplementation("androidx.test.espresso:espresso-contrib:$espressoVersion") |
88 dualTestImplementation("androidx.test.espresso:espresso-intents:$espressoVersion") |
99 dualTestImplementation("androidx.test.espresso:espresso-intents:$espressoVersion") |
89 |
100 |
90 // assertions |
101 // assertions |
91 dualTestImplementation("com.google.truth:truth:1.0") |
102 dualTestImplementation("com.google.truth:truth:1.4.4") |
92 dualTestImplementation("androidx.test.ext:truth:1.3.0-alpha01") |
103 dualTestImplementation("androidx.test.ext:truth:1.6.0") |
93 |
104 |
94 // mock |
105 // mock |
95 testImplementation("io.mockk:mockk:1.13.2") |
106 testImplementation("io.mockk:mockk:1.13.8") |
96 androidTestImplementation("io.mockk:mockk-android:1.13.2") |
107 androidTestImplementation("io.mockk:mockk-android:1.13.8") |
97 testImplementation("org.robolectric:robolectric:$robolectricVersion") |
108 testImplementation("org.robolectric:robolectric:$robolectricVersion") |
98 |
109 |
99 constraints { |
110 constraints { |
100 dualTestImplementation(kotlin("reflect")) { |
111 dualTestImplementation(kotlin("reflect")) { |
101 because("Use the kotlin version that we use") |
112 because("Use the kotlin version that we use") |