Skip to content

Commit 6540a5f

Browse files
committed
add androidTest
1 parent 1827c22 commit 6540a5f

File tree

15 files changed

+88
-24
lines changed

15 files changed

+88
-24
lines changed

app/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ apply plugin: 'androidx.navigation.safeargs.kotlin'
55
apply plugin: 'dagger.hilt.android.plugin'
66
apply plugin: 'com.github.konifar.gradle.unused-resources-remover'
77
apply from: '../depgraph.gradle'
8-
apply from: '../shared_deps.gradle'
9-
apply from: '../test_deps.gradle'
8+
apply from: '../deps_shared.gradle'
9+
apply from: '../deps_test.gradle'
10+
apply from: '../deps_android_test.gradle'
1011
apply from: '../ktlint.gradle'
1112

1213
android {
@@ -17,7 +18,7 @@ android {
1718
targetSdkVersion configs.targetSdkVersion
1819
versionCode configs.versionCode
1920
versionName configs.versionName
20-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
21+
testInstrumentationRunner "com.takusemba.jethub.CustomAndroidJUnitRunner"
2122
}
2223
buildTypes {
2324
release {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.takusemba.jethub
2+
3+
import android.app.Application
4+
import android.content.Context
5+
import androidx.test.runner.AndroidJUnitRunner
6+
import dagger.hilt.android.testing.HiltTestApplication
7+
8+
class CustomAndroidJUnitRunner : AndroidJUnitRunner() {
9+
10+
override fun newApplication(cl: ClassLoader, name: String, context: Context): Application {
11+
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
12+
}
13+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.takusemba.jethub
2+
3+
import androidx.test.ext.junit.rules.activityScenarioRule
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import com.google.common.truth.Truth.assertThat
6+
import com.takusemba.jethub.ui.activity.MainActivity
7+
import dagger.hilt.android.testing.HiltAndroidRule
8+
import dagger.hilt.android.testing.HiltAndroidTest
9+
import okhttp3.OkHttpClient
10+
import org.junit.Rule
11+
import org.junit.Test
12+
import org.junit.runner.RunWith
13+
import javax.inject.Inject
14+
15+
@HiltAndroidTest
16+
@RunWith(AndroidJUnit4::class)
17+
class MainTabFragmentTest {
18+
19+
@Inject
20+
lateinit var okHttpClient: OkHttpClient
21+
22+
@get:Rule(order = 0)
23+
var hiltRule = HiltAndroidRule(this)
24+
25+
@get:Rule(order = 1)
26+
var activityRule = activityScenarioRule<MainActivity>()
27+
28+
@Test
29+
fun mainTabFragmentTest() {
30+
hiltRule.inject()
31+
assertThat(okHttpClient).isNotNull()
32+
}
33+
}

base/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
33
apply plugin: "kotlin-kapt"
44
apply plugin: 'dagger.hilt.android.plugin'
5-
apply from: '../shared_deps.gradle'
6-
apply from: '../test_deps.gradle'
5+
apply from: '../deps_shared.gradle'
6+
apply from: '../deps_test.gradle'
77
apply from: '../ktlint.gradle'
88

99
android {

constants.gradle

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ project.ext {
2626
groupie: "2.8.0",
2727

2828
// library (test)
29-
junit: "4.12",
29+
junit: "4.13",
3030
]
3131

3232
deps = [
@@ -56,7 +56,7 @@ project.ext {
5656
constraintLayout: "androidx.constraintlayout:constraintlayout:2.0.0-beta7",
5757
coreKtx: "androidx.core:core-ktx:1.5.0-alpha01",
5858
activityKtx: "androidx.activity:activity-ktx:1.2.0-alpha06",
59-
fragmentKtx: "androidx.fragment:fragment-ktx:1.2.0-alpha06",
59+
fragmentKtx: "androidx.fragment:fragment-ktx:1.3.0-alpha06",
6060

6161
// compose
6262
composeCore: "androidx.ui:ui-core:${versions.compose}",
@@ -86,6 +86,7 @@ project.ext {
8686
daggerCompiler: "com.google.dagger:dagger-compiler:${versions.dagger}",
8787
daggerHilt: "com.google.dagger:hilt-android:${versions.daggerHilt}",
8888
daggerHiltCompiler: "com.google.dagger:hilt-android-compiler:${versions.daggerHilt}",
89+
daggerHiltTesting: "com.google.dagger:hilt-android-testing:${versions.daggerHilt}",
8990
androidHilt: "androidx.hilt:hilt-common:${versions.androidHilt}",
9091
androidHiltViewModel: "androidx.hilt:hilt-lifecycle-viewmodel:${versions.androidHilt}",
9192
androidHiltCompiler: "androidx.hilt:hilt-compiler:${versions.androidHilt}",
@@ -112,8 +113,14 @@ project.ext {
112113
// test
113114
junit: "junit:junit:${versions.junit}",
114115
mockk: "io.mockk:mockk:1.9.3",
115-
truth: "com.google.truth:truth:1.0",
116-
testCore: "android.arch.core:core-testing:1.1.0",
116+
truth: "com.google.truth:truth:1.0.1",
117+
archCore: "androidx.arch.core:core-testing:2.1.0",
118+
119+
// android test
120+
testCore: "androidx.test:core:1.2.0",
121+
espresso: "androidx.test.espresso:espresso-core:3.2.0",
122+
extJunitKtx: "androidx.test.ext:junit-ktx:1.1.1",
123+
extTruth: "androidx.test.ext:truth:1.2.0",
117124

118125
// lint
119126
ktlint: "com.pinterest:ktlint:0.37.2",

data/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ apply plugin: 'kotlin-android'
33
apply plugin: "kotlin-kapt"
44
apply plugin: 'kotlinx-serialization'
55
apply plugin: 'dagger.hilt.android.plugin'
6-
apply from: '../shared_deps.gradle'
7-
apply from: '../test_deps.gradle'
6+
apply from: '../deps_shared.gradle'
7+
apply from: '../deps_test.gradle'
88
apply from: '../ktlint.gradle'
99

1010
android {

deps_android_test.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
dependencies {
2+
androidTestImplementation deps.junit
3+
androidTestImplementation deps.truth
4+
androidTestImplementation deps.testCore
5+
androidTestImplementation deps.extJunitKtx
6+
androidTestImplementation deps.extTruth
7+
androidTestImplementation deps.espresso
8+
androidTestImplementation deps.daggerHiltTesting
9+
kaptAndroidTest deps.daggerHiltCompiler
10+
}
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dependencies {
22
testImplementation(deps.junit)
33
testImplementation(deps.truth)
4-
testImplementation(deps.testCore)
4+
testImplementation(deps.archCore)
55
testImplementation(deps.mockk)
66
}

dynamic/developer/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ apply plugin: "com.android.dynamic-feature"
22
apply plugin: 'kotlin-android'
33
apply plugin: "kotlin-kapt"
44
apply plugin: 'dagger.hilt.android.plugin'
5-
apply from: '../../shared_deps.gradle'
6-
apply from: '../../test_deps.gradle'
5+
apply from: '../../deps_shared.gradle'
6+
apply from: '../../deps_test.gradle'
77
apply from: '../../ktlint.gradle'
88

99
android {

0 commit comments

Comments
 (0)