From 4b4c33655e8d9c62a8f028a5adf337c4e2e5d960 Mon Sep 17 00:00:00 2001 From: dacost13 Date: Tue, 14 Sep 2021 22:30:32 +0100 Subject: [PATCH] Changes in Xml files and Manifest // express testing in MainActivity --- app/build.gradle | 6 ++ .../booksharing21/MainActivityExpress.java | 66 +++++++++++++++++++ app/src/main/AndroidManifest.xml | 2 +- .../booksharing21/RegisterActivity.java | 2 +- .../example/booksharing21/SplashActivity.java | 6 +- app/src/main/res/layout/activity_bprofile.xml | 3 +- app/src/main/res/layout/activity_main.xml | 3 +- app/src/main/res/layout/activity_register.xml | 19 +++--- .../booksharing21/RegisterValidationTest.java | 2 - 9 files changed, 89 insertions(+), 20 deletions(-) create mode 100644 app/src/androidTest/java/com/example/booksharing21/MainActivityExpress.java diff --git a/app/build.gradle b/app/build.gradle index b439549..381e6ce 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -49,8 +49,14 @@ dependencies { testImplementation 'org.mockito:mockito-core:1.10.19' testImplementation 'androidx.test:core:1.0.0' testImplementation "com.google.truth:truth:1.1.2" + testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + androidTestImplementation 'androidx.test:runner:1.1.0' + androidTestImplementation 'androidx.test:rules:1.1.0' + androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0' + + implementation 'com.google.android.material:material:1.2.0' diff --git a/app/src/androidTest/java/com/example/booksharing21/MainActivityExpress.java b/app/src/androidTest/java/com/example/booksharing21/MainActivityExpress.java new file mode 100644 index 0000000..ae44c78 --- /dev/null +++ b/app/src/androidTest/java/com/example/booksharing21/MainActivityExpress.java @@ -0,0 +1,66 @@ +package com.example.booksharing21; + + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; +import static androidx.test.espresso.action.ViewActions.typeText; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; + +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.SmallTest; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +@SmallTest +public class MainActivityExpress { + + + private static final String VALID_Email = "john.doe@outlook.com"; + + private static final String VALID_Password = "1234john"; + + @Rule + public ActivityScenarioRule activityRule = + new ActivityScenarioRule<>(MainActivity.class); + + + // android developers https://developer.android.com/training/testing/espresso/basics + // checking users credentials + + @Test + public void ValidCredentials() { + onView(withId(R.id.email)).perform(typeText(VALID_Email), closeSoftKeyboard()); + onView(withId(R.id.password)).perform(typeText(VALID_Password),closeSoftKeyboard()); } + @Test + public void WrongEmail(){ + onView(withId(R.id.email)).perform(typeText("john"),closeSoftKeyboard()); + onView(withId(R.id.password)).perform(typeText(VALID_Password),closeSoftKeyboard()); } + + @Test + public void WrongPassword(){ + onView(withId(R.id.email)).perform(typeText(VALID_Email),closeSoftKeyboard()); + onView(withId(R.id.password)).perform(typeText("doe"),closeSoftKeyboard()); } + + @Test + public void NoCredentials(){ + onView(withId(R.id.email)).perform(typeText(""),closeSoftKeyboard()); + onView(withId(R.id.password)).perform(typeText(""),closeSoftKeyboard()); } + + + @Test + public void RegButton(){ onView(withId(R.id.reg)).perform(click()); } + @Test + public void logButton(){ onView(withId(R.id.log)).perform(click()).check(matches(isDisplayed())); } + + + + + +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7e78343..b7a2b85 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -29,8 +29,8 @@ + - diff --git a/app/src/main/java/com/example/booksharing21/RegisterActivity.java b/app/src/main/java/com/example/booksharing21/RegisterActivity.java index 23e4ff4..d554611 100644 --- a/app/src/main/java/com/example/booksharing21/RegisterActivity.java +++ b/app/src/main/java/com/example/booksharing21/RegisterActivity.java @@ -231,7 +231,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL String username = editusername.getText().toString().trim(); if (username.isEmpty()) { - editusername.setError("Username is Required"); + editusername.setError("Invalid Username"); editusername.requestFocus(); return Boolean.FALSE; }else{ diff --git a/app/src/main/java/com/example/booksharing21/SplashActivity.java b/app/src/main/java/com/example/booksharing21/SplashActivity.java index 4e5ae9e..d2e6325 100644 --- a/app/src/main/java/com/example/booksharing21/SplashActivity.java +++ b/app/src/main/java/com/example/booksharing21/SplashActivity.java @@ -1,11 +1,11 @@ package com.example.booksharing21; -import androidx.appcompat.app.AppCompatActivity; - import android.content.Intent; import android.os.Bundle; import android.os.Handler; +import androidx.appcompat.app.AppCompatActivity; + public class SplashActivity extends AppCompatActivity { private static int SPLASH_TIME_OUT = 4000; @@ -21,7 +21,7 @@ public class SplashActivity extends AppCompatActivity { new Handler().postDelayed(new Runnable() { @Override public void run() { - Intent homeIntent = new Intent(SplashActivity.this, com.example.booksharing21.MainActivity.class); + Intent homeIntent = new Intent(SplashActivity.this,MainActivity.class); startActivity(homeIntent); finish(); } diff --git a/app/src/main/res/layout/activity_bprofile.xml b/app/src/main/res/layout/activity_bprofile.xml index 04501ea..f4f03c6 100644 --- a/app/src/main/res/layout/activity_bprofile.xml +++ b/app/src/main/res/layout/activity_bprofile.xml @@ -3,8 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" - tools:context=".BProfileActivity"> + android:layout_height="match_parent"> + android:layout_height="match_parent"> + app:srcCompat="@drawable/booksharinglogo" + android:contentDescription="Logo" />