Skip to content

Commit c5b6915

Browse files
committed
Smoke test of any example
1 parent 715a64b commit c5b6915

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

MPChartExample/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ dependencies {
3232
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.4"
3333
androidTestUtil "androidx.test.services:test-services:1.4.2"
3434
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.0"
35+
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.5.0'
3536
}
3637

MPChartExample/src/androidTest/java/com/xxmassdeveloper/mpchartexample/StartTest.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@ package com.xxmassdeveloper.mpchartexample
22

33
import androidx.test.core.graphics.writeToTestStorage
44
import androidx.test.espresso.Espresso
5+
import androidx.test.espresso.Espresso.onData
6+
import androidx.test.espresso.action.ViewActions.click
57
import androidx.test.espresso.matcher.ViewMatchers
8+
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
9+
import androidx.test.espresso.matcher.ViewMatchers.withId
610
import androidx.test.espresso.screenshot.captureToBitmap
711
import androidx.test.ext.junit.rules.activityScenarioRule
812
import androidx.test.ext.junit.runners.AndroidJUnit4
913
import com.xxmassdeveloper.mpchartexample.notimportant.MainActivity
14+
import org.hamcrest.CoreMatchers.allOf
15+
import org.hamcrest.CoreMatchers.anything
16+
import org.junit.After
17+
import org.junit.Before
1018
import org.junit.Rule
1119
import org.junit.Test
1220
import org.junit.rules.TestName
1321
import org.junit.runner.RunWith
22+
import androidx.test.espresso.intent.Intents
23+
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
1424

1525
@RunWith(AndroidJUnit4::class)
1626
class StartTest {
@@ -21,10 +31,36 @@ class StartTest {
2131
@get:Rule
2232
var nameRule = TestName()
2333

34+
@Before
35+
fun setUp() {
36+
Intents.init()
37+
}
38+
39+
@After
40+
fun cleanUp() {
41+
Intents.release()
42+
}
43+
2444
@Test
2545
fun smokeTestSimplyStart() {
2646
Espresso.onView(ViewMatchers.isRoot())
2747
.captureToBitmap()
2848
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
49+
50+
MainActivity.menuItems.forEachIndexed { index, contentItem ->
51+
contentItem.clazz?.let {
52+
println("Intended ${index}-${it.simpleName}")
53+
54+
onData(anything())
55+
.inAdapterView(allOf(withId(R.id.listView1), isCompletelyDisplayed()))
56+
.atPosition(index).perform(click())
57+
58+
Espresso.onView(ViewMatchers.isRoot())
59+
.captureToBitmap()
60+
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-${index}-${it.simpleName}")
61+
Intents.intended(hasComponent(it.name))
62+
Espresso.pressBack()
63+
}
64+
}
2965
}
3066
}

0 commit comments

Comments
 (0)