Skip to content

Commit

Permalink
Merge pull request #286 from wealthfront/migration-int-test
Browse files Browse the repository at this point in the history
Add basic integration test to sample app
  • Loading branch information
cmathew authored Sep 25, 2023
2 parents 37214e3 + 33e9699 commit e670df6
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 18 deletions.
1 change: 1 addition & 0 deletions buildSrc/src/main/java/Libs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ object Libs {
const val extJunit = "androidx.test.ext:junit:$junitTestExtVersion"
const val extJunitKtx = "androidx.test.ext:junit-ktx:$junitTestExtVersion"
const val espressoCore = "androidx.test.espresso:espresso-core:$espressoVersion"
const val espressoContrib = "androidx.test.espresso:espresso-contrib:$espressoVersion"
const val rx2idler = "com.squareup.rx.idler:rx2-idler:0.11.0"

const val lintApi = "com.android.tools.lint:lint-api:$lintVersion"
Expand Down
17 changes: 14 additions & 3 deletions magellan-sample-migration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ android {
dependencies {
implementation project(':magellan-library')
implementation project(':magellan-legacy')
implementation project(':magellan-rx')
implementation project(':magellan-rx2')

implementation Libs.appCompat
implementation Libs.dagger
kapt Libs.daggerCompiler

implementation Libs.glide
implementation Libs.retrofit
implementation Libs.rxjavaAdapter
implementation Libs.rxandroid
implementation Libs.rxjava2
implementation Libs.rxAndroid2
implementation Libs.rxJava2Adapter
implementation Libs.jackson
implementation Libs.okhttp
implementation Libs.coroutines
Expand All @@ -76,5 +77,15 @@ dependencies {
testImplementation Libs.robolectric

androidTestImplementation Libs.extJunit
androidTestImplementation Libs.rxjava2
androidTestImplementation Libs.rx2idler
androidTestImplementation Libs.espressoCore
androidTestImplementation Libs.espressoContrib
androidTestImplementation Libs.testCore
androidTestImplementation Libs.testCoreKtx
androidTestImplementation Libs.testRunner
androidTestImplementation Libs.testRules

androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestUtil 'androidx.test:orchestrator:1.4.1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.wealthfront.magellan

import androidx.test.runner.AndroidJUnitRunner
import com.squareup.rx2.idler.Rx2Idler
import io.reactivex.plugins.RxJavaPlugins

class IntegrationTestRunner : AndroidJUnitRunner() {

override fun onStart() {
RxJavaPlugins.setInitIoSchedulerHandler(Rx2Idler.create("RxJava 2.x IO Scheduler"))
RxJavaPlugins.setInitComputationSchedulerHandler(Rx2Idler.create("RxJava 2.x Computation Scheduler"))

super.onStart()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.wealthfront.magellan.uitest

import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.launchActivity
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.wealthfront.magellan.sample.migration.MainActivity
import com.wealthfront.magellan.sample.migration.R
import org.junit.Before
import org.junit.Test

class NavigationTest {

lateinit var activityScenario: ActivityScenario<MainActivity>

@Before
fun setup() {
activityScenario = launchActivity()
}

@Test
fun visitRetriever() {
onView(withText("Akita")).perform(click())
onView(withId(R.id.dogDetailsView)).check(matches(isDisplayed()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import dagger.Module;
import dagger.Provides;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.jackson.JacksonConverterFactory;
import rx.schedulers.Schedulers;

@Module
final class AppModule {
Expand Down Expand Up @@ -42,7 +42,7 @@ DogApi provideDogApi(Retrofit retrofit) {
Retrofit provideRetrofit(OkHttpClient httpClient) {
return new Retrofit.Builder()
.baseUrl(DOG_BASE_URL)
.addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io()))
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(JacksonConverterFactory.create())
.client(httpClient)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.wealthfront.magellan.sample.migration.api

import com.fasterxml.jackson.annotation.JsonProperty
import io.reactivex.Observable
import retrofit2.http.GET
import retrofit2.http.Path
import rx.Observable

interface DogApi {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import android.view.View
import android.widget.Toast
import com.wealthfront.magellan.Screen
import com.wealthfront.magellan.lifecycle.attachFieldToLifecycle
import com.wealthfront.magellan.rx.RxUnsubscriber
import com.wealthfront.magellan.rx2.RxDisposer
import com.wealthfront.magellan.sample.migration.R
import com.wealthfront.magellan.sample.migration.SampleApplication.Companion.app
import com.wealthfront.magellan.sample.migration.api.DogApi
import com.wealthfront.magellan.sample.migration.toolbar.ToolbarHelper
import com.wealthfront.magellan.transitions.CircularRevealTransition
import rx.android.schedulers.AndroidSchedulers.mainThread
import io.reactivex.android.schedulers.AndroidSchedulers.mainThread
import javax.inject.Inject

class DogDetailsScreen(private val breed: String) : Screen<DogDetailsView>() {

@Inject lateinit var api: DogApi
private val rxUnsubscriber by attachFieldToLifecycle(RxUnsubscriber())
private val rxUnsubscriber by attachFieldToLifecycle(RxDisposer())

override fun createView(context: Context): DogDetailsView {
app(context).injector().inject(this)
Expand All @@ -30,7 +30,7 @@ class DogDetailsScreen(private val breed: String) : Screen<DogDetailsView>() {
Toast.makeText(activity, "Menu - Notifications clicked", Toast.LENGTH_SHORT).show()
}
ToolbarHelper.setMenuColor(R.color.water)
rxUnsubscriber.autoUnsubscribe(
rxUnsubscriber.autoDispose(
api.getRandomImageForBreed(breed)
.observeOn(mainThread())
.subscribe {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import android.content.DialogInterface
import com.wealthfront.magellan.LegacyStep
import com.wealthfront.magellan.OpenForMocking
import com.wealthfront.magellan.lifecycle.attachFieldToLifecycle
import com.wealthfront.magellan.rx.RxUnsubscriber
import com.wealthfront.magellan.rx2.RxDisposer
import com.wealthfront.magellan.sample.migration.AppComponentContainer
import com.wealthfront.magellan.sample.migration.api.DogApi
import rx.android.schedulers.AndroidSchedulers
import io.reactivex.android.schedulers.AndroidSchedulers.mainThread
import javax.inject.Inject

@OpenForMocking
class HelpScreen(private val goToBreedsStep: () -> Unit) : LegacyStep<HelpView>() {

@Inject lateinit var api: DogApi
private val rxUnsubscriber by attachFieldToLifecycle(RxUnsubscriber())
private val rxUnsubscriber by attachFieldToLifecycle(RxDisposer())

override fun onCreate(context: Context) {
(context.applicationContext as AppComponentContainer).injector().inject(this)
Expand All @@ -27,9 +27,9 @@ class HelpScreen(private val goToBreedsStep: () -> Unit) : LegacyStep<HelpView>(
}

override fun onShow(context: Context) {
rxUnsubscriber.autoUnsubscribe(
rxUnsubscriber.autoDispose(
api.getRandomImageForBreed("husky")
.observeOn(AndroidSchedulers.mainThread())
.observeOn(mainThread())
.subscribe {
view!!.setDogPic(it.message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/dogDetailsView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:gravity="center"
android:orientation="vertical"
android:background="@android:color/white"
>

<ImageView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.wealthfront.magellan.sample.migration.TestAppComponent
import com.wealthfront.magellan.sample.migration.TestSampleApplication
import com.wealthfront.magellan.sample.migration.api.DogApi
import com.wealthfront.magellan.sample.migration.api.DogMessage
import io.reactivex.Observable
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -20,7 +21,6 @@ import org.mockito.MockitoAnnotations.initMocks
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
import rx.Observable
import javax.inject.Inject

@RunWith(RobolectricTestRunner::class)
Expand Down

0 comments on commit e670df6

Please sign in to comment.