From 634672db0f66f4b1c6a063fcb880bf739fc6bfe0 Mon Sep 17 00:00:00 2001 From: stargateprovider Date: Tue, 7 Dec 2021 10:36:27 +0200 Subject: [PATCH] Moved UC4test to new branch --- MobileAuthApp/app/build.gradle | 2 + .../tarkvaraprojekt/mobileauthapp/UC4Test.kt | 62 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt diff --git a/MobileAuthApp/app/build.gradle b/MobileAuthApp/app/build.gradle index 38896fb..2fd1c20 100644 --- a/MobileAuthApp/app/build.gradle +++ b/MobileAuthApp/app/build.gradle @@ -44,7 +44,9 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test:rules:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + debugImplementation 'androidx.fragment:fragment-testing:1.4.0' //To use activityViewModels implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt new file mode 100644 index 0000000..3c03951 --- /dev/null +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -0,0 +1,62 @@ +package com.tarkvaraprojekt.mobileauthapp + +//import androidx.fragment.app.testing.launchFragmentInContainer +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.IdlingPolicies +import androidx.test.espresso.NoMatchingViewException +import androidx.test.espresso.action.ViewActions.* +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.rule.ActivityTestRule + +import org.junit.* +import org.junit.runner.RunWith +import java.util.concurrent.TimeUnit + +@RunWith(AndroidJUnit4::class) +class UC4Test { + @get:Rule + var activityActivityTestRule: ActivityTestRule = ActivityTestRule( + MainActivity::class.java + ) + + @Before + fun setUp() { + IdlingPolicies.setMasterPolicyTimeout(3, TimeUnit.SECONDS) + IdlingPolicies.setIdlingResourceTimeout(3, TimeUnit.SECONDS) + activityActivityTestRule.activity + .supportFragmentManager.beginTransaction() + } + + @After + fun tearDown() { + } + + fun navigateToCANView() { + onView(withId(R.id.menu_settings_option)).perform(click()) + try { + // Delete existing CAN + onView(withText(R.string.can_delete)).perform(click()) + } catch (ignore: NoMatchingViewException) {} + + onView(withId(R.id.can_menu_action)).perform(click()) + } + + @Test + fun validCAN() { + navigateToCANView() + onView(withText(R.string.can_helper_text)).check(matches(isDisplayed())) + onView(supportsInputMethods()).perform(typeText("123456")) + onView(withText(R.string.can_delete)).perform(closeSoftKeyboard()) + + onView(withText(R.string.can_status_saved)).check(matches(isDisplayed())) + } + + @Test + fun invalidCAN() { + navigateToCANView() + onView(supportsInputMethods()).perform(typeText("12345")) + onView(withText(R.string.can_helper_text)).check(matches(isDisplayed())) + } +} \ No newline at end of file