[android] - add integration test suite

This commit is contained in:
tobrun
2019-03-15 13:40:28 +01:00
committed by Tobrun
parent 5ea450b14b
commit 76df7d9cee
16 changed files with 378 additions and 306 deletions

View File

@@ -0,0 +1,60 @@
package com.mapbox.mapboxsdk.integration
import android.content.Intent
import android.support.test.InstrumentationRegistry
import android.support.test.uiautomator.*
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert
import org.junit.Before
const val LAUNCH_TIMEOUT = 2500L
private const val TEST_APP_PACKAGE = "com.mapbox.mapboxsdk.testapp"
abstract class BaseIntegrationTest {
protected lateinit var device: UiDevice
@Before
open fun beforeTest() {
// Initialize UiDevice instance
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
// Start from the home screen
device.pressHome()
// Wait for launcher
val launcherPackage: String = device.launcherPackageName
MatcherAssert.assertThat(launcherPackage, CoreMatchers.notNullValue())
device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT)
// Launch the app
val context = InstrumentationRegistry.getInstrumentation().context
val intent = context.packageManager.getLaunchIntentForPackage(TEST_APP_PACKAGE).apply {
// Clear out any previous instances
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
}
context.startActivity(intent)
// Wait for the app to appear
device.wait(
Until.hasObject(By.pkg(TEST_APP_PACKAGE).depth(0)),
LAUNCH_TIMEOUT
)
}
fun openFeature(featureName: String) {
scrollRecyclerViewTo(featureName)
device.findObject(UiSelector().text(featureName)).clickAndWaitForNewWindow()
device.waitForIdle(LAUNCH_TIMEOUT)
}
fun scrollRecyclerViewTo(recycleItem: String) {
val appView = UiScrollable(UiSelector().scrollable(true))
appView.scrollIntoView(UiSelector().text(recycleItem))
}
fun pressHomeReturnWithRecentApps(){
device.pressRecentApps()
device.findObject(UiSelector().text(InstrumentationRegistry.getTargetContext().getString(InstrumentationRegistry.getTargetContext().applicationInfo.labelRes))).click()
}
}

View File

@@ -0,0 +1,59 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
import android.support.test.runner.AndroidJUnit4
import android.support.test.uiautomator.UiSelector
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
/**
* Regression test that validates MapFragment integration on the backstack
*/
@RunWith(AndroidJUnit4::class)
class FragmentBackStackTest : BaseIntegrationTest() {
@Before
override fun beforeTest() {
super.beforeTest()
openFeature("Backstack Map Fragment")
}
@Test
@LargeTest
fun backPressedOnBackStack() {
device.waitForIdle()
clickReplaceFragmentButton()
device.waitForIdle()
backPressBackStack()
}
@Test
@LargeTest
fun backPressedOnBackStackResumed(){
device.waitForIdle()
clickReplaceFragmentButton()
device.waitForIdle()
pressHomeReturnWithRecentApps()
device.waitForIdle()
backPressBackStack()
}
@Test
@LargeTest
fun finishOnBackStack() {
device.waitForIdle()
clickReplaceFragmentButton()
device.waitForIdle()
device.findObject(UiSelector().description("Navigate up")).click()
}
private fun clickReplaceFragmentButton(){
device.findObject(UiSelector().text("REPLACE WITH EMPTY FRAGMENT")).click()
}
private fun backPressBackStack(){
device.pressBack() // pops fragment, showing map
device.pressBack() // finish activity
}
}

View File

@@ -0,0 +1,27 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
import android.support.test.runner.AndroidJUnit4
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
/**
* Regression test that validates reopening an Activity with a GLSurfaceView
*/
@RunWith(AndroidJUnit4::class)
class GLSurfaceViewReopenTest : BaseIntegrationTest() {
@Before
override fun beforeTest() {
super.beforeTest()
openFeature("Simple Map")
}
@Test
@LargeTest
fun reopenSimpleMapActivity() {
pressHomeReturnWithRecentApps()
device.waitForIdle()
}
}

View File

@@ -0,0 +1,30 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
import android.support.test.runner.AndroidJUnit4
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
/**
* Regression test that validates if a GLSurfaceView surface can be recreated without crashing.
*/
@RunWith(AndroidJUnit4::class)
class GLSurfaceViewReuseTest : BaseIntegrationTest() {
@Before
override fun beforeTest() {
super.beforeTest()
openFeature("RecyclerView GLSurfaceView")
}
@Test
@LargeTest
fun scrollRecylerView() {
device.waitForIdle()
scrollRecyclerViewTo("Twenty-one")
device.waitForIdle()
scrollRecyclerViewTo("One")
device.waitForIdle()
}
}

View File

@@ -0,0 +1,29 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
import android.support.test.runner.AndroidJUnit4
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class OrientationChangeTest : BaseIntegrationTest() {
@Before
override fun beforeTest() {
super.beforeTest()
openFeature("Simple Map")
}
@Test
@LargeTest
fun rotateSimpleMap() {
device.setOrientationLeft()
device.waitForIdle()
device.setOrientationNatural()
device.waitForIdle()
device.setOrientationRight()
device.waitForIdle()
device.setOrientationNatural()
}
}

View File

@@ -0,0 +1,29 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
import android.support.test.runner.AndroidJUnit4
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.lang.Thread.sleep
/**
* Regression test that validates reopening an Activity with a TextureView
*/
@RunWith(AndroidJUnit4::class)
class TextureViewReopenTest : BaseIntegrationTest() {
@Before
override fun beforeTest() {
super.beforeTest()
openFeature("TextureView debug")
}
@Test
@LargeTest
fun reopenTextureViewDebugActivity() {
pressHomeReturnWithRecentApps()
device.waitForIdle()
sleep(LAUNCH_TIMEOUT)
}
}

View File

@@ -0,0 +1,29 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
import android.support.test.runner.AndroidJUnit4
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
/**
* Regression test that validates if a GLSurfaceView surface can be recreated without crashing.
*/
@RunWith(AndroidJUnit4::class)
class TextureViewReuseTest : BaseIntegrationTest() {
@Before
override fun beforeTest() {
super.beforeTest()
openFeature("RecyclerView TextureView")
}
@Test
@LargeTest
fun scrollRecylerView() {
scrollRecyclerViewTo("Twenty-one")
device.waitForIdle()
scrollRecyclerViewTo("One")
device.waitForIdle()
}
}

View File

@@ -0,0 +1,37 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
import android.support.test.runner.AndroidJUnit4
import android.support.test.uiautomator.UiSelector
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
/**
* Regression test that validates MapFragment integration with a ViewPager
*/
@RunWith(AndroidJUnit4::class)
class ViewPagerScrollTest : BaseIntegrationTest() {
@Before
override fun beforeTest() {
super.beforeTest()
openFeature("ViewPager")
}
@Test
@LargeTest
fun scrollViewPager() {
for (i in 1..5) {
clickTab(i)
}
for (i in 4 downTo 0) {
clickTab(i)
}
}
private fun clickTab(index: Int) {
device.findObject(UiSelector().text("Page $index")).click()
}
}

View File

@@ -1,72 +0,0 @@
package com.mapbox.mapboxsdk.maps
import android.content.Intent
import android.support.test.InstrumentationRegistry
import android.support.test.InstrumentationRegistry.getTargetContext
import android.support.test.filters.SdkSuppress
import android.support.test.runner.AndroidJUnit4
import android.support.test.uiautomator.By
import android.support.test.uiautomator.UiDevice
import android.support.test.uiautomator.UiSelector
import android.support.test.uiautomator.Until
import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
private const val BASIC_SAMPLE_PACKAGE = "com.mapbox.mapboxsdk.testapp"
private const val LAUNCH_TIMEOUT = 5000L
@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = 18)
class GLSurfaceViewReopenTest {
private lateinit var device: UiDevice
@Before
fun startSimpleMapActivityFromHomeScreen() {
// Initialize UiDevice instance
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
// Start from the home screen
device.pressHome()
// Wait for launcher
val launcherPackage: String = device.launcherPackageName
assertThat(launcherPackage, notNullValue())
device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT)
// Launch the app
val context = InstrumentationRegistry.getInstrumentation().context
val intent = context.packageManager.getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE).apply {
// Clear out any previous instances
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
}
context.startActivity(intent)
// Wait for the app to appear
device.wait(
Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)),
LAUNCH_TIMEOUT
)
// open SimpleMapActivity
device.findObject(UiSelector().text("Simple Map")).clickAndWaitForNewWindow()
// wait for idle
device.waitForIdle(LAUNCH_TIMEOUT)
}
@Test
fun reopenSimpleMapActivity() {
// press recent apps button to pause the app
device.pressRecentApps()
// return to app
device.findObject(UiSelector().text(getTargetContext().getString(getTargetContext().applicationInfo.labelRes))).click()
// wait for idle
device.waitForIdle(LAUNCH_TIMEOUT)
}
}

View File

@@ -1,41 +0,0 @@
package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.testapp.action.OrientationAction;
import com.mapbox.mapboxsdk.testapp.action.WaitAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseTest;
import com.mapbox.mapboxsdk.testapp.activity.camera.CameraAnimationTypeActivity;
import org.junit.Test;
import static com.mapbox.mapboxsdk.testapp.action.OrientationAction.orientationLandscape;
import static com.mapbox.mapboxsdk.testapp.action.OrientationAction.orientationLandscapeReverse;
import static com.mapbox.mapboxsdk.testapp.action.OrientationAction.orientationPortrait;
import static com.mapbox.mapboxsdk.testapp.action.OrientationAction.orientationPortraitReverse;
public class OrientationTest extends BaseTest {
@Test
public void testChangeDeviceOrientation() {
OrientationAction.invoke(orientationLandscape());
WaitAction.invoke(2200);
OrientationAction.invoke(orientationPortrait());
WaitAction.invoke(2500);
OrientationAction.invoke(orientationLandscapeReverse());
WaitAction.invoke(500);
OrientationAction.invoke(orientationPortraitReverse());
WaitAction.invoke(1250);
OrientationAction.invoke(orientationLandscape());
WaitAction.invoke(750);
OrientationAction.invoke(orientationPortrait());
WaitAction.invoke(950);
OrientationAction.invoke(orientationLandscapeReverse());
OrientationAction.invoke(orientationPortraitReverse());
OrientationAction.invoke(orientationLandscape());
OrientationAction.invoke(orientationPortrait());
}
@Override
protected Class getActivityClass() {
return CameraAnimationTypeActivity.class;
}
}

View File

@@ -1,70 +0,0 @@
package com.mapbox.mapboxsdk.maps
import android.content.Intent
import android.support.test.InstrumentationRegistry
import android.support.test.filters.SdkSuppress
import android.support.test.runner.AndroidJUnit4
import android.support.test.uiautomator.*
import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
private const val BASIC_SAMPLE_PACKAGE = "com.mapbox.mapboxsdk.testapp"
private const val LAUNCH_TIMEOUT = 5000L
@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = 18)
class TextureViewReopenTest {
private lateinit var device: UiDevice
@Before
fun startSimpleMapActivityFromHomeScreen() {
// Initialize UiDevice instance
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
// Start from the home screen
device.pressHome()
// Wait for launcher
val launcherPackage: String = device.launcherPackageName
assertThat(launcherPackage, notNullValue())
device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT)
// Launch the app
val context = InstrumentationRegistry.getInstrumentation().context
val intent = context.packageManager.getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE).apply {
// Clear out any previous instances
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
}
context.startActivity(intent)
// Wait for the app to appear
device.wait(
Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)),
LAUNCH_TIMEOUT
)
// open TextureView debug activity
val appView = UiScrollable(UiSelector().scrollable(true))
appView.scrollIntoView(UiSelector().text("TextureView debug"))
device.findObject(UiSelector().text("TextureView debug")).clickAndWaitForNewWindow()
// wait for idle
device.waitForIdle(LAUNCH_TIMEOUT)
}
@Test
fun reopenTextureViewDebugActivity() {
// press recent apps button
device.pressRecentApps()
// return to app
device.findObject(UiSelector().text(InstrumentationRegistry.getTargetContext().getString(InstrumentationRegistry.getTargetContext().applicationInfo.labelRes))).click()
// wait for idle
device.waitForIdle(LAUNCH_TIMEOUT)
}
}