-
Notifications
You must be signed in to change notification settings - Fork 19
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
1 parent
0b329ae
commit 4bbc5e1
Showing
10 changed files
with
328 additions
and
19 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
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
106 changes: 106 additions & 0 deletions
106
sample/src/androidTest/java/convalida/sample/AnotherSampleActivityTest.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,106 @@ | ||
package convalida.sample; | ||
|
||
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 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.assertion.ViewAssertions.doesNotExist; | ||
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.withText; | ||
|
||
/** | ||
* @author Wellington Costa on 14/11/2017. | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class AnotherSampleActivityTest { | ||
|
||
@Rule | ||
public ActivityTestRule<AnotherSampleActivity> activityTestRule = new ActivityTestRule<>(AnotherSampleActivity.class); | ||
|
||
@Test | ||
public void executeValidationsWithEmptyFields() { | ||
onView(withId(R.id.validate_button)) | ||
.perform(closeSoftKeyboard()) | ||
.check(matches(isDisplayed())) | ||
.perform(click()); | ||
|
||
onView(withText(R.string.field_required)) | ||
.check(matches(isDisplayed())); | ||
|
||
onView(withText(R.string.min_3_characters)) | ||
.check(matches(isDisplayed())); | ||
|
||
onView(withText(R.string.only_numbers)) | ||
.check(matches(isDisplayed())); | ||
|
||
onView(withText(R.string.invalid_phone)) | ||
.check(matches(isDisplayed())); | ||
} | ||
|
||
@Test | ||
public void clearAllValidations() { | ||
onView(withId(R.id.validate_button)) | ||
.perform(closeSoftKeyboard()) | ||
.check(matches(isDisplayed())) | ||
.perform(click()); | ||
|
||
onView(withId(R.id.clear_button)) | ||
.check(matches(isDisplayed())) | ||
.perform(click()); | ||
|
||
onView(withText(R.string.field_required)) | ||
.check(doesNotExist()); | ||
|
||
onView(withText(R.string.min_3_characters)) | ||
.check(doesNotExist()); | ||
|
||
onView(withText(R.string.only_numbers)) | ||
.check(doesNotExist()); | ||
|
||
onView(withText(R.string.invalid_phone)) | ||
.check(doesNotExist()); | ||
} | ||
|
||
@Test | ||
public void testNameField() { | ||
TestUtils.testFieldWithEmptyValue(R.id.validate_button, R.string.field_required); | ||
|
||
TestUtils.testFieldWithAValidValue(R.id.name_field, R.string.field_required, "Wellington"); | ||
} | ||
|
||
@Test | ||
public void testNicknameField() { | ||
TestUtils.testFieldWithEmptyValue(R.id.validate_button, R.string.min_3_characters); | ||
|
||
TestUtils.testFieldWithAnInvalidValue(R.id.nickname_field, R.string.min_3_characters, "We"); | ||
|
||
TestUtils.testFieldWithAValidValue(R.id.nickname_field, R.string.min_3_characters, "Well"); | ||
} | ||
|
||
@Test | ||
public void testAgeField() { | ||
TestUtils.testFieldWithEmptyValue(R.id.validate_button, R.string.only_numbers); | ||
|
||
TestUtils.testFieldWithAnInvalidValue(R.id.age_field, R.string.only_numbers, "abc"); | ||
|
||
TestUtils.testFieldWithAValidValue(R.id.age_field, R.string.only_numbers, "21"); | ||
} | ||
|
||
@Test | ||
public void testPhoneField() { | ||
TestUtils.testFieldWithEmptyValue(R.id.validate_button, R.string.invalid_phone); | ||
|
||
TestUtils.testFieldWithAnInvalidValue(R.id.phone_field, R.string.invalid_phone, "558586846409"); | ||
|
||
TestUtils.testFieldWithAValidValue(R.id.phone_field, R.string.invalid_phone, "+55(85)8684-6409"); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
sample/src/androidTest/java/convalida/sample/MainActivityTest.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,39 @@ | ||
package convalida.sample; | ||
|
||
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 static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.action.ViewActions.click; | ||
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; | ||
|
||
/** | ||
* @author Wellington Costa on 12/11/2017. | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class MainActivityTest { | ||
|
||
@Rule | ||
public ActivityTestRule<MainActivity> activityTestRule = new ActivityTestRule<>(MainActivity.class); | ||
|
||
@Test | ||
public void showSample1() throws Exception { | ||
onView(withId(R.id.sample_1)) | ||
.check(matches(isDisplayed())) | ||
.perform(click()); | ||
} | ||
|
||
@Test | ||
public void showSample2() throws Exception { | ||
onView(withId(R.id.sample_2)) | ||
.check(matches(isDisplayed())) | ||
.perform(click()); | ||
} | ||
|
||
} |
103 changes: 103 additions & 0 deletions
103
sample/src/androidTest/java/convalida/sample/SampleActivityTest.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,103 @@ | ||
package convalida.sample; | ||
|
||
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 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.assertion.ViewAssertions.doesNotExist; | ||
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.withText; | ||
|
||
/** | ||
* @author Wellington Costa on 12/11/2017. | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class SampleActivityTest { | ||
|
||
@Rule | ||
public ActivityTestRule<SampleActivity> activityTestRule = new ActivityTestRule<>(SampleActivity.class); | ||
|
||
@Test | ||
public void executeValidationsWithEmptyFields() { | ||
onView(withId(R.id.validate_button)) | ||
.perform(closeSoftKeyboard()) | ||
.check(matches(isDisplayed())) | ||
.perform(click()); | ||
|
||
onView(withText(R.string.field_required)) | ||
.check(matches(isDisplayed())); | ||
|
||
onView(withText(R.string.invalid_email)) | ||
.check(matches(isDisplayed())); | ||
|
||
onView(withText(R.string.invalid_password)) | ||
.check(matches(isDisplayed())); | ||
} | ||
|
||
@Test | ||
public void clearAllValidations() { | ||
onView(withId(R.id.validate_button)) | ||
.perform(closeSoftKeyboard()) | ||
.check(matches(isDisplayed())) | ||
.perform(click()); | ||
|
||
onView(withId(R.id.clear_button)) | ||
.check(matches(isDisplayed())) | ||
.perform(click()); | ||
|
||
onView(withText(R.string.field_required)) | ||
.check(doesNotExist()); | ||
|
||
onView(withText(R.string.invalid_email)) | ||
.check(doesNotExist()); | ||
|
||
onView(withText(R.string.invalid_password)) | ||
.check(doesNotExist()); | ||
|
||
onView(withText(R.string.passwords_not_match)) | ||
.check(doesNotExist()); | ||
} | ||
|
||
@Test | ||
public void testNameField() { | ||
TestUtils.testFieldWithEmptyValue(R.id.validate_button, R.string.field_required); | ||
|
||
TestUtils.testFieldWithAValidValue(R.id.name_field, R.string.field_required, "Wellington"); | ||
} | ||
|
||
@Test | ||
public void testEmailField() { | ||
TestUtils.testFieldWithEmptyValue(R.id.validate_button, R.string.invalid_email); | ||
|
||
TestUtils.testFieldWithAnInvalidValue(R.id.email_field, R.string.invalid_email, "well@email"); | ||
|
||
TestUtils.testFieldWithAValidValue(R.id.email_field, R.string.invalid_email, "[email protected]"); | ||
} | ||
|
||
@Test | ||
public void testPasswordField() { | ||
TestUtils.testFieldWithEmptyValue(R.id.validate_button, R.string.invalid_password); | ||
|
||
TestUtils.testFieldWithAnInvalidValue(R.id.password_field, R.string.invalid_password, "asdASD"); | ||
|
||
TestUtils.testFieldWithAValidValue(R.id.password_field, R.string.invalid_password, "asdASD123"); | ||
} | ||
|
||
@Test | ||
public void testConfirmPasswordField() { | ||
TestUtils.testFieldWithAValidValue(R.id.password_field, R.string.invalid_password, "asdASD123"); | ||
|
||
TestUtils.testFieldWithAnInvalidValue(R.id.confirm_password_field, R.string.passwords_not_match, "asdASD"); | ||
|
||
TestUtils.testFieldWithAValidValue(R.id.confirm_password_field, R.string.passwords_not_match, "asdASD123"); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
sample/src/androidTest/java/convalida/sample/TestUtils.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,50 @@ | ||
package convalida.sample; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.action.ViewActions.clearText; | ||
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.doesNotExist; | ||
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.withText; | ||
|
||
/** | ||
* @author Wellington Costa on 14/11/2017. | ||
*/ | ||
|
||
class TestUtils { | ||
|
||
static void testFieldWithEmptyValue(int fieldResId, int errorMessageResId) { | ||
onView(withId(fieldResId)) | ||
.check(matches(isDisplayed())) | ||
.perform(closeSoftKeyboard()) | ||
.perform(click()); | ||
|
||
onView(withText(errorMessageResId)) | ||
.check(matches(isDisplayed())); | ||
} | ||
|
||
static void testFieldWithAValidValue(int fieldResId, int errorMessageResId, String value) { | ||
onView(withId(fieldResId)) | ||
.perform(clearText(), typeText(value)) | ||
.perform(closeSoftKeyboard()) | ||
.check(matches(withText(value))); | ||
|
||
onView(withText(errorMessageResId)) | ||
.check(doesNotExist()); | ||
} | ||
|
||
static void testFieldWithAnInvalidValue(int fieldResId, int errorMessageResId, String value) { | ||
onView(withId(fieldResId)) | ||
.perform(clearText(), typeText(value)) | ||
.perform(closeSoftKeyboard()) | ||
.check(matches(withText(value))); | ||
|
||
onView(withText(errorMessageResId)) | ||
.check(matches(isDisplayed())); | ||
} | ||
|
||
} |
Oops, something went wrong.