Skip to content

Commit b5e228f

Browse files
committed
✅ Add sample app test cases
1 parent 4914f2a commit b5e228f

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

.idea/misc.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ dependencies {
4343
implementation 'androidx.appcompat:appcompat:1.3.1'
4444
implementation 'androidx.core:core-ktx:1.6.0'
4545
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
46-
testImplementation 'junit:junit:4.13.1'
46+
47+
testImplementation 'junit:junit:4.13.2'
48+
androidTestImplementation 'androidx.test:core-ktx:1.4.0'
49+
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.3'
50+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
51+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
52+
4753
androidTestImplementation 'androidx.test:runner:1.4.0'
4854
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
4955

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.techpaliyal.androidkotlinmvvm
2+
3+
import android.view.View
4+
import androidx.test.espresso.FailureHandler
5+
import org.hamcrest.Matcher
6+
7+
class CustomFailureHandler: FailureHandler {
8+
override fun handle(error: Throwable?, viewMatcher: Matcher<View>?) {
9+
assert(false)
10+
}
11+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.techpaliyal.androidkotlinmvvm.ui.activity
2+
3+
import androidx.test.espresso.Espresso.*
4+
import androidx.test.espresso.FailureHandler
5+
import androidx.test.espresso.action.ViewActions.click
6+
import androidx.test.espresso.matcher.ViewMatchers.withId
7+
import androidx.test.ext.junit.rules.ActivityScenarioRule
8+
import androidx.test.ext.junit.runners.AndroidJUnit4
9+
import com.techpaliyal.androidkotlinmvvm.R
10+
import org.junit.Assert.*
11+
import org.junit.Before
12+
import org.junit.Rule
13+
import org.junit.Test
14+
import org.junit.runner.RunWith
15+
16+
@RunWith(AndroidJUnit4::class)
17+
class MainActivityTest(){
18+
19+
@Rule
20+
@JvmField
21+
public var activityScenarioRule = ActivityScenarioRule(MainActivity::class.java)
22+
23+
@Before
24+
fun before(){
25+
/* setFailureHandler(FailureHandler { error, viewMatcher ->
26+
27+
})*/
28+
}
29+
30+
@Test
31+
fun launchBasicActivity(){
32+
onView(withId(R.id.btnBasicListing)).perform(click()).withFailureHandler { error, viewMatcher -> }
33+
34+
35+
}
36+
37+
@Test
38+
fun launchMultiSelectActivity(){
39+
onView(withId(R.id.btnMultiSelect)).perform(click()).withFailureHandler { error, viewMatcher -> }
40+
41+
42+
}
43+
44+
@Test
45+
fun launchLoadingActivity(){
46+
onView(withId(R.id.btnLoadingListing)).perform(click()).withFailureHandler { error, viewMatcher -> }
47+
}
48+
49+
@Test
50+
fun launchShimmerActivity(){
51+
onView(withId(R.id.btnShimmerListing)).perform(click()).withFailureHandler { error, viewMatcher -> }
52+
}
53+
54+
55+
@Test
56+
fun launchPaginationActivity(){
57+
onView(withId(R.id.btnPaginationListing)).perform(click()).withFailureHandler { error, viewMatcher -> }
58+
}
59+
60+
@Test
61+
fun launchBindingAdapterActivity(){
62+
onView(withId(R.id.btnBindingAdapter)).perform(click()).withFailureHandler { error, viewMatcher -> }
63+
}
64+
65+
@Test
66+
fun launchMultipleViewsActivity(){
67+
onView(withId(R.id.btnMultipleViews)).perform(click()).withFailureHandler { error, viewMatcher -> }
68+
onView(withId(R.id.btnSchoolListing)).perform(click()).withFailureHandler { error, viewMatcher -> }
69+
pressBack()
70+
onView(withId(R.id.btnChatListing)).perform(click()).withFailureHandler { error, viewMatcher -> }
71+
pressBack()
72+
}
73+
74+
}

0 commit comments

Comments
 (0)