This repository has been archived by the owner on May 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
459 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/src/androidTest/java/io/github/marktony/espresso/about/AboutScreenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.github.marktony.espresso.about; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.filters.SmallTest; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import io.github.marktony.espresso.R; | ||
import io.github.marktony.espresso.ui.PrefsActivity; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.assertion.ViewAssertions.matches; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withParent; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withText; | ||
import static org.hamcrest.core.AllOf.allOf; | ||
|
||
/** | ||
* Created by lizhaotailang on 2017/5/13. | ||
* Tests for the {@link io.github.marktony.espresso.ui.AboutFragment}. | ||
*/ | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@SmallTest | ||
public class AboutScreenTest { | ||
|
||
/** | ||
* {@link ActivityTestRule} is a JUnit {@link Rule @Rule} to launch your activity under test. | ||
* | ||
* <p> | ||
* Rules are interceptors which are executed for each test method and are important building | ||
* blocks of Junit tests. | ||
*/ | ||
@Rule | ||
public ActivityTestRule<PrefsActivity> mPrefsActivityTestRule | ||
= new ActivityTestRule<PrefsActivity>(PrefsActivity.class){ | ||
@Override | ||
protected Intent getActivityIntent() { | ||
Context targetContext = InstrumentationRegistry.getInstrumentation() | ||
.getTargetContext(); | ||
Intent intent = new Intent(targetContext, PrefsActivity.class); | ||
intent.putExtra(PrefsActivity.EXTRA_FLAG, PrefsActivity.FLAG_ABOUT); | ||
return intent; | ||
} | ||
}; | ||
|
||
@Test | ||
public void test_AboutScreenDisplayed() { | ||
onView(allOf(withParent(withId(R.id.toolbar)), | ||
withText(R.string.nav_about))) | ||
.check(matches(isDisplayed())); | ||
} | ||
|
||
} |
159 changes: 159 additions & 0 deletions
159
app/src/androidTest/java/io/github/marktony/espresso/addpackage/AddPackageScreenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package io.github.marktony.espresso.addpackage; | ||
|
||
import android.os.Build; | ||
import android.support.test.espresso.matcher.ViewMatchers; | ||
import android.support.test.filters.LargeTest; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import io.github.marktony.espresso.R; | ||
import io.github.marktony.espresso.mvp.addpackage.AddPackageActivity; | ||
|
||
import static android.support.test.InstrumentationRegistry.getInstrumentation; | ||
import static android.support.test.InstrumentationRegistry.getTargetContext; | ||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.action.ViewActions.click; | ||
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; | ||
import static android.support.test.espresso.action.ViewActions.typeText; | ||
import static android.support.test.espresso.assertion.ViewAssertions.matches; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withParent; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withText; | ||
import static org.hamcrest.core.AllOf.allOf; | ||
|
||
/** | ||
* Created by lizhaotailang on 2017/5/14. | ||
* Tests the components of {@link AddPackageActivity} layout. | ||
*/ | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@LargeTest | ||
public class AddPackageScreenTest { | ||
|
||
private String validPackageNumber; | ||
private String invalidPackageNumber; | ||
|
||
/** | ||
* {@link ActivityTestRule} is a JUnit {@link Rule @Rule} to launch your activity under test. | ||
* | ||
* <p> | ||
* Rules are interceptors which are executed for each test method and are important building | ||
* blocks of Junit tests. | ||
*/ | ||
@Rule | ||
public ActivityTestRule<AddPackageActivity> mAddPackageActivityTestRule | ||
= new ActivityTestRule<>(AddPackageActivity.class); | ||
|
||
@Before | ||
public void initNumbers() { | ||
validPackageNumber = "958381347318"; | ||
invalidPackageNumber = "12345"; | ||
} | ||
|
||
@Before | ||
public void grantCameraPermission() { | ||
// In M+, trying to call a number will trigger a runtime dialog. Make sure | ||
// the permission is granted before running this test. | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
getInstrumentation().getUiAutomation().executeShellCommand( | ||
"pm grant " + getTargetContext().getPackageName() | ||
+ " android.permission.CAMERA"); | ||
} | ||
} | ||
|
||
@Test | ||
public void test_AddPackageScreenDisplayed() { | ||
// Check that the toolbar title was correct. | ||
onView(withText(R.string.activity_add_package)) | ||
.check(matches(withParent(withId(R.id.toolbar)))); | ||
} | ||
|
||
@Test | ||
public void clickOnFab_ShowErrorTip() { | ||
// Click the floating action button without inputting anything. | ||
onView(withId(R.id.fab)).perform(click()); | ||
|
||
// Check that the snack bar was displayed. | ||
onView(allOf(withId(android.support.design.R.id.snackbar_text), | ||
withText(R.string.wrong_number_and_check))) | ||
.check(matches(isDisplayed())); | ||
} | ||
|
||
@Test | ||
public void typeValidNumber_ShowHomeScreen() { | ||
onView(withId(R.id.editTextNumber)) | ||
.check(matches(isCompletelyDisplayed())); | ||
|
||
// Type the valid number. | ||
onView(withId(R.id.editTextNumber)) | ||
.perform(typeText(validPackageNumber), closeSoftKeyboard()); | ||
|
||
// Click the floating action button. | ||
onView(withId(R.id.fab)).perform(click()); | ||
|
||
// Check that the package name edit text was filled automatically. | ||
String name = mAddPackageActivityTestRule.getActivity().getString(R.string.package_name_default_pre) | ||
+ validPackageNumber.substring(0, 4); | ||
onView(withId(R.id.editTextName)) | ||
.check(matches(withText(name))); | ||
|
||
} | ||
|
||
@Test | ||
public void typeInvalidNumber_ShowErrorTip() { | ||
onView(withId(R.id.editTextNumber)) | ||
.check(matches(isCompletelyDisplayed())); | ||
|
||
// Type the valid number. | ||
onView(withId(R.id.editTextNumber)) | ||
.perform(typeText(invalidPackageNumber), closeSoftKeyboard()); | ||
|
||
// Click the floating action button. | ||
onView(withId(R.id.fab)).perform(click()); | ||
|
||
// Check that the package name edit text was filled automatically. | ||
String name = mAddPackageActivityTestRule.getActivity().getString(R.string.package_name_default_pre) | ||
+ invalidPackageNumber.substring(0, 4); | ||
onView(withId(R.id.editTextName)) | ||
.check(matches(withText(name))); | ||
|
||
// Check that the snack bar with error message was displayed. | ||
onView(allOf(withId(android.support.design.R.id.snackbar_text), | ||
withText(R.string.wrong_number_and_check))) | ||
.check(matches(isDisplayed())); | ||
} | ||
|
||
@Test | ||
public void typeEmptyNumber_ShowErrorTip() { | ||
onView(withId(R.id.editTextNumber)) | ||
.check(matches(isCompletelyDisplayed())); | ||
|
||
// Type empty. | ||
onView(withId(R.id.editTextNumber)) | ||
.perform(typeText(""), closeSoftKeyboard()); | ||
|
||
// Click the floating action button. | ||
onView(withId(R.id.fab)).perform(click()); | ||
|
||
// Check that the progress bar was gone. | ||
onView(withId(R.id.progressBar)) | ||
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.GONE))); | ||
|
||
// Check that the package name edit text was filled automatically. | ||
onView(withId(R.id.editTextName)) | ||
.check(matches(withText(""))); | ||
|
||
// Check that the snack bar with error message was displayed. | ||
onView(allOf(withId(android.support.design.R.id.snackbar_text), | ||
withText(R.string.wrong_number_and_check))) | ||
.check(matches(isDisplayed())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.