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
@LargeTest | |
class MovieFragmentTest { | |
private lateinit var activityScenario: ActivityScenario<MainActivity> | |
private val mockWebServer = MockWebServer() | |
@Before | |
fun setup() { | |
mockWebServer.start(port) | |
IdlingRegistry.getInstance().register( | |
OkHttp3IdlingResource.create( |
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
class MovieScreen : Screen<MovieScreen>() { | |
val recycler = KRecyclerView({ withId(R.id.moviesRv) }, itemTypeBuilder = { | |
itemType(MovieScreen::Item) | |
}) | |
class Item(parent: Matcher<View>) : KRecyclerItem<Item>(parent) { | |
val image: KImageView = KImageView(parent) { withId(R.id.movieIv) } | |
val name: KTextView = KTextView(parent) { withId(R.id.movieName) } | |
val rating: KRatingBar = KRatingBar(parent) { withId(R.id.movieRatingBar) } | |
} |
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
fun dispatcherWithCustomBody() = object : Dispatcher() { | |
override fun dispatch(request: RecordedRequest): MockResponse { | |
with(request.path) { | |
val response = MockResponse().setResponseCode(200) | |
return when { | |
this?.contains("/images") == true -> response | |
.setBody(FileReader.readTestResourceFile("movie_images_response.json")) | |
else -> response | |
.setBody(FileReader.readTestResourceFile("success_response.json")) | |
} |
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
@Test | |
fun recyclerview_second_item_should_be_visible() { | |
mockWebServer.dispatcher = object : Dispatcher() { | |
override fun dispatch(request: RecordedRequest): MockResponse { | |
return MockResponse() | |
.setResponseCode(200) | |
.setBody(FileReader.readTestResourceFile("success_response.json")) | |
} | |
} | |
} |
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
object OkHttpProvider { | |
// Timeout for the network requests | |
private const val REQUEST_TIMEOUT = 3L | |
private var okHttpClient: OkHttpClient? = null | |
fun getOkHttpClient(): OkHttpClient { | |
return if (okHttpClient == null) { | |
val okHttpClient = OkHttpClient.Builder() |
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
@LargeTest | |
class MovieFragmentTest { | |
private val mockWebServer = MockWebServer() | |
@Before | |
fun setup() { | |
mockWebServer.start(port) | |
IdlingRegistry.getInstance().register( | |
OkHttp3IdlingResource.create( | |
"okhttp", |
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
object FileReader { | |
fun readTestResourceFile(fileName: String): String { | |
try { | |
val inputStream = (InstrumentationRegistry.getInstrumentation().targetContext | |
.applicationContext as MovieTestApp).assets.open(fileName) | |
val builder = StringBuilder() | |
val reader = InputStreamReader(inputStream, "UTF-8") | |
reader.readLines().forEach { | |
builder.append(it) | |
} |
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
{ | |
"results": [ | |
{ | |
"adult": false, | |
"backdrop_path": "/srYya1ZlI97Au4jUYAktDe3avyA.jpg", | |
"genre_ids": [ | |
14, | |
28, | |
12 | |
], |
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
@LargeTest | |
class MovieFragmentTest { | |
private lateinit var activityScenario: ActivityScenario<MainActivity> | |
private val mockWebServer = MockWebServer() | |
@Before | |
fun setup() { | |
mockWebServer.start(port) | |
IdlingRegistry.getInstance().register( | |
OkHttp3IdlingResource.create( |
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
class MovieTestRunner : AndroidJUnitRunner() { | |
override fun newApplication(cl: ClassLoader?, className: String?, | |
context: Context?): Application { | |
return super.newApplication(cl, MovieTestApp::class.java.name, context) | |
} | |
} |
NewerOlder