Skip to content

Commit

Permalink
Fix: Added test case for webview fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
PruthiviRaj27 committed May 9, 2023
1 parent 9579ebd commit 7536ed8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ dependencies {
androidTestImplementation "androidx.test:core:1.4.0"
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.test:rules:1.4.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"

// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package `in`.testpress.testpress.fragment

import android.os.Bundle
import androidx.fragment.app.testing.FragmentScenario
import androidx.test.espresso.Espresso
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.runners.AndroidJUnit4
import `in`.testpress.testpress.R
import `in`.testpress.testpress.ui.fragments.WebViewFragment
import androidx.fragment.app.testing.launchFragmentInContainer
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class WebViewFragmentTest {

@Test
fun testWebViewFragment() {
val url = "https://www.google.com"
val bundle = WebViewFragment.createArguments(url)

// Launch the fragment
val scenario: FragmentScenario<WebViewFragment> = launchFragmentInContainer(
bundle, R.style.AppTheme
)

// Check that the web view is displayed
Espresso.onView(ViewMatchers.withId(R.id.web_view))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
}

private fun WebViewFragment.Companion.createArguments(url: String): Bundle {
return Bundle().apply {
putString(URL_TO_OPEN, url)
}
}
}

0 comments on commit 7536ed8

Please sign in to comment.