Slide 1

Slide 1 text

1

Slide 2

Slide 2 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Rainer Weiss Kip Thorne Barry Barish

Slide 3

Slide 3 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Rainer Weiss Kip Thorne Barry Barish Nobel laureates in Physics 2017 Gravitational waves

Slide 4

Slide 4 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 General relativity

Slide 5

Slide 5 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017

Slide 6

Slide 6 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 a thousand part of a proton

Slide 7

Slide 7 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 2 black holes melded 1.3 Billion years ago Gravitational waves detected

Slide 8

Slide 8 text

8 REACTIVE STATEMANAGEMENT WITH MODEL-VIEW-INTENT

Slide 9

Slide 9 text

9 HELLO I’M HANNES

Slide 10

Slide 10 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 MVP MVC MVVM MVC MVI

Slide 11

Slide 11 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 MVP MVC MVVM MVI

Slide 12

Slide 12 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 What is a Model?

Slide 13

Slide 13 text

class PersonsPresenter : Presenter { fun loadPersons() { view?.showLoading(true) backend.loadPersons({ persons : List -> view?.showPersons(persons) }, { error: Throwable -> view?.showError(error) }) } }

Slide 14

Slide 14 text

class PersonsPresenter : Presenter { fun loadPersons() { view?.showLoading(true) backend.loadPersons({ persons : List -> view?.showPersons(persons) }, { error: Throwable -> view?.showError(error) }) } }

Slide 15

Slide 15 text

class PersonsPresenter : Presenter { fun loadPersons(){ view?.showLoading(true) backend.loadPersons({ persons : List -> view?.showPersons(persons) }, { error: Throwable -> view?.showError(error) }) } }

Slide 16

Slide 16 text

class PersonsPresenter : Presenter { fun loadPersons(){ view?.showLoading(true) backend.loadPersons({ persons : List -> view?.showPersons(persons) }, { error: Throwable -> view?.showError(error) }) } }

Slide 17

Slide 17 text

class PersonsPresenter : Presenter { fun loadPersons(){ view?.showLoading(true) backend.loadPersons({ persons : List -> view?.showPersons(persons) }, { error: Throwable -> view?.showError(error) }) } }

Slide 18

Slide 18 text

class PersonsPresenter : Presenter { fun loadPersons(){ view?.showLoading(true) // Displays a ProgressBar backend.loadPersons({ persons : List -> view?.showPersons(persons) // Displays a ProgressBar }, { error: Throwable -> view?.showError(error) // Displays a error message }) } }

Slide 19

Slide 19 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 What is a Model?

Slide 20

Slide 20 text

class PersonsViewModel : ViewModel { val loadingLiveData : MutableLiveData … fun loadPersons(){ loadingLiveData.setValue((true) backend.loadPersons({ persons : List -> loadingLiveData.setValue( false ) personsLiveData.setValue( persons ) }, { error: Throwable -> loadingLiveData.setValue( false ) errorLiveData.setValue( error ) }) } }

Slide 21

Slide 21 text

class PersonsViewModel : ViewModel { val loadingLiveData : MutableLiveData … fun loadPersons(){ loadingLiveData.setValue((true) backend.loadPersons({ persons : List -> loadingLiveData.setValue( false ) personsLiveData.setValue( persons ) }, { error: Throwable -> loadingLiveData.setValue( false ) errorLiveData.setValue( error ) }) } }

Slide 22

Slide 22 text

class PersonsViewModel : ViewModel { val loadingLiveData : MutableLiveData … fun loadPersons(){ loadingLiveData.setValue((true) backend.loadPersons({ persons : List -> loadingLiveData.setValue( false ) personsLiveData.setValue( persons ) }, { error: Throwable -> loadingLiveData.setValue( false ) errorLiveData.setValue( error ) }) } }

Slide 23

Slide 23 text

class PersonsViewModel : ViewModel { val loadingLiveData : MutableLiveData … fun loadPersons(){ loadingLiveData.setValue((true) backend.loadPersons({ persons : List -> loadingLiveData.setValue( false ) personsLiveData.setValue( persons ) }, { error: Throwable -> loadingLiveData.setValue( false ) errorLiveData.setValue( error ) }) } }

Slide 24

Slide 24 text

class PersonsViewModel : ViewModel { val loadingLiveData : MutableLiveData … fun loadPersons(){ loadingLiveData.setValue((true) backend.loadPersons({ persons : List -> loadingLiveData.setValue( false ) personsLiveData.setValue( persons ) }, { error: Throwable -> loadingLiveData.setValue( false ) errorLiveData.setValue( error ) }) } }

Slide 25

Slide 25 text

class PersonsViewModel : ViewModel { val loadingLiveData : MutableLiveData … fun loadPersons(){ loadingLiveData.setValue((true) backend.loadPersons({ persons : List -> loadingLiveData.setValue( false ) personsLiveData.setValue( persons ) }, { error: Throwable -> loadingLiveData.setValue( false ) errorLiveData.setValue( error ) }) } }

Slide 26

Slide 26 text

class PersonsViewModel : ViewModel { val loadingLiveData : MutableLiveData … fun loadPersons(){ loadingLiveData.setValue((true) backend.loadPersons({ persons : List -> loadingLiveData.setValue( false ) personsLiveData.setValue( persons ) }, { error: Throwable -> loadingLiveData.setValue( false ) errorLiveData.setValue( error ) }) } }

Slide 27

Slide 27 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 What is a Model?

Slide 28

Slide 28 text

data class PersonsModel ( val loading : boolean, val persons : List?, val error : Throwable? )

Slide 29

Slide 29 text

class PersonsPresenter : Presenter { fun loadPersons(){ view?.render(PersonsModel ( true, null, null) ) backend.loadPersons({ persons : List -> view?.render(PersonsModel ( false, persons, null) ) }, { error: Throwable -> view?.render(PersonsModel ( false, null, error) ) }) } }

Slide 30

Slide 30 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Model == State

Slide 31

Slide 31 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 How do we change State?

Slide 32

Slide 32 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 User

Slide 33

Slide 33 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 User

Slide 34

Slide 34 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 User Business Logic intent

Slide 35

Slide 35 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 User Business Logic intent state

Slide 36

Slide 36 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 User Business Logic intent state render(state)

Slide 37

Slide 37 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Model-View-Intent

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

interface SearchView { fun searchIntent() : Observable fun render(viewState : SearchViewState) }

Slide 41

Slide 41 text

data class SearchViewState ( val error : Throwable? val loading: boolean val result : List? )

Slide 42

Slide 42 text

class SearchFragment : Fragment , SearchView { ... override fun searchIntent() : Observable { return RxSearchView.queryTextChanges(searchView) // Thanks Jake Wharton } }

Slide 43

Slide 43 text

class SearchFragment : Fragment , SearchView { ... override fun render( viewState : SearchViewState) { if (viewState.loading) renderLoading() else if (viewState.result != null) renderResult(viewState.result) else if (viewState.error != null) renderError() else throw IllegalStateException("Unknown ViewState") } }

Slide 44

Slide 44 text

class SearchPresenter : MviBasePresenter { val SearchInteractor searchInteractor; override fun bindIntents() { val searchState : Observable = intent(SearchView::searchIntent) .filter { term -> term.size >= 3 } .switchMap(searchInteractor::search) subscribeViewState(searchState, SearchView::render) } }

Slide 45

Slide 45 text

class SearchInteractor { val searchEngine : SearchEngine // Makes http calls fun search(searchString : String) : Observable{ return searchEngine.searchFor(searchString) // Observable> .map(products -> SearchViewState(false, products, null)) .startWith(SearchViewState(true, null, null)) .onErrorReturn(error -> SearchViewState(false, null, error)); } }

Slide 46

Slide 46 text

class SearchInteractor { val searchEngine : SearchEngine // Makes http calls fun search(searchString : String) : Observable{ return searchEngine.searchFor(searchString) // Observable> .map(products -> new SearchViewState(false, products, null)) .startWith(new SearchViewState(true, null, null)) .onErrorReturn(error -> new SearchViewState(false, null, error)); } }

Slide 47

Slide 47 text

class SearchInteractor { val searchEngine : SearchEngine // Makes http calls fun search(searchString : String) : Observable{ return searchEngine.searchFor(searchString) // Observable> .map(products -> new SearchViewState(false, products, null)) .startWith(new SearchViewState(true, null, null)) .onErrorReturn(error -> new SearchViewState(false, null, error)); } }

Slide 48

Slide 48 text

class SearchInteractor { val searchEngine : SearchEngine // Makes http calls fun search(searchString : String) : Observable{ return searchEngine.searchFor(searchString) // Observable> .map(products -> new SearchViewState(false, products, null)) .startWith(new SearchViewState(true, null, null)) .onErrorReturn(error -> new SearchViewState(false, null, error)); } }

Slide 49

Slide 49 text

class SearchInteractor { val searchEngine : SearchEngine // Makes http calls fun search(searchString : String) : Observable{ return searchEngine.searchFor(searchString) // Observable> .map(products -> new SearchViewState(false, products, null)) .startWith(new SearchViewState(true, null, null)) .onErrorReturn(error -> new SearchViewState(false, null, error)); } }

Slide 50

Slide 50 text

Search … searchIntent view.render( model )

Slide 51

Slide 51 text

C searchIntent filter() C view.render( model )

Slide 52

Slide 52 text

Ca searchIntent filter() C Ca view.render( model )

Slide 53

Slide 53 text

Cam searchIntent Cam filter() C Ca view.render( model )

Slide 54

Slide 54 text

Cam searchIntent filter() flatMap() view.render( model ) Cam C Ca Cam

Slide 55

Slide 55 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) Cam C Ca Cam

Slide 56

Slide 56 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L view.render( SearchViewState.Loading) Cam C Ca Cam

Slide 57

Slide 57 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L view.render( SearchViewState.Loading) Cam C Ca Cam

Slide 58

Slide 58 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L view.render( SearchViewState.Loading) Cam C Ca Cam

Slide 59

Slide 59 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L view.render( SearchViewState.Loading) Cam C Ca Cam

Slide 60

Slide 60 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L view.render( SearchViewState.Loading) Cam C Ca Cam

Slide 61

Slide 61 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L Cam C Ca Cam Cam

Slide 62

Slide 62 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L Cam C Ca Cam Cam

Slide 63

Slide 63 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L Cam C Ca Cam Cam

Slide 64

Slide 64 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L Cam C Ca Cam Cam

Slide 65

Slide 65 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L map( new SR() ) Cam C Ca Cam Cam

Slide 66

Slide 66 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L map( new SR() ) Cam C Ca Cam Cam

Slide 67

Slide 67 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L map( new SR() ) SR view.render( SearchViewState.SearchResult ) Cam C Ca Cam Cam

Slide 68

Slide 68 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L map( new SR() ) SR view.render( SearchViewState.SearchResult ) Cam C Ca Cam Cam

Slide 69

Slide 69 text

Cam searchIntent filter() flatMap() startWith( new Loading() ) L map( new SR() ) SR view.render( SearchViewState.SearchResult ) Cam C Ca Cam Cam

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

interface HomeView { fun loadFirstPageIntent() : Observable fun loadNextPageIntent() : Observable fun pullToRefreshIntent() : Observable fun loadAllProductsFromCategoryIntent() : Observable fun render(viewState : HomeViewState) }

Slide 75

Slide 75 text

class HomePresenter : MviBasePresenter { val HomeFeedLoader feedLoader; override fun bindIntents() { val firstPage : Observable = ... val pullToRefresh : Observable = ... val nextPage : Observable = ... val loadMoreFromCategory : Observable = ... val allIntents : Observable = Observable.merge(firstPage, pullToRefresh, nextPage, loadMoreFromCategory) stateObservable : Observable = allIntents.scan(this::reduceState) subscribeViewState(stateObservable, HomeView::render) }

Slide 76

Slide 76 text

class HomePresenter : MviBasePresenter { val HomeFeedLoader feedLoader; override fun bindIntents() { val firstPage : Observable = ... val pullToRefresh : Observable = ... val nextPage : Observable = ... val loadMoreFromCategory : Observable = ... val allIntents : Observable = Observable.merge(firstPage, pullToRefresh, nextPage, loadMoreFromCategory) stateObservable : Observable = allIntents.scan(this::reduceState) subscribeViewState(stateObservable, HomeView::render) }

Slide 77

Slide 77 text

class HomePresenter : MviBasePresenter { val HomeFeedLoader feedLoader; override fun bindIntents() { val firstPage : Observable = ... val pullToRefresh : Observable = ... val nextPage : Observable = ... val loadMoreFromCategory : Observable = ... val allIntents : Observable = Observable.merge(firstPage, pullToRefresh, nextPage, loadMoreFromCategory) stateObservable : Observable = allIntents.scan(this::reduceState) subscribeViewState(stateObservable, HomeView::render) }

Slide 78

Slide 78 text

class HomePresenter : MviBasePresenter { val HomeFeedLoader feedLoader; override fun bindIntents() { val firstPage : Observable = ... val pullToRefresh : Observable = ... val nextPage : Observable = ... val loadMoreFromCategory : Observable = ... val allIntents : Observable = Observable.merge(firstPage, pullToRefresh, nextPage, loadMoreFromCategory) stateObservable : Observable = allIntents.scan(this::reduceState) subscribeViewState(stateObservable, HomeView::render) }

Slide 79

Slide 79 text

fun reduceState ( previous : HomeViewState, feedLoaderState : FeedLoaderState ) : HomeViewState { val newState : HomeViewState = … // compute the new State // by taking previous state and foo into account return newState; }

Slide 80

Slide 80 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 State Driven by Business Logic

Slide 81

Slide 81 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Microservices

Slide 82

Slide 82 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 state

Slide 83

Slide 83 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 state state

Slide 84

Slide 84 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017

Slide 85

Slide 85 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Independent UI Components

Slide 86

Slide 86 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017

Slide 87

Slide 87 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017

Slide 88

Slide 88 text

interface SelectedCountToolbar { fun deleteSelectedIntent() : Observable fun render(viewState : Int) }

Slide 89

Slide 89 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Reproducible States

Slide 90

Slide 90 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017

Slide 91

Slide 91 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017

Slide 92

Slide 92 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Testing

Slide 93

Slide 93 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 assertEquals (expectedState, actualState)

Slide 94

Slide 94 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 More Integration Tests Less Unit tests

Slide 95

Slide 95 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 More Integration Tests Less Unit Tests

Slide 96

Slide 96 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Why Unit Tests - Test code in isolation - Reliable (not flaky) - Run fast - Testing UI as part of an Integration Test is senseless, since View is dump

Slide 97

Slide 97 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 2 Unit Tests, 0 Integration Test

Slide 98

Slide 98 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 2 Unit Tests, 0 Integration Test

Slide 99

Slide 99 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 What if we architect and write Test Code the way we write production code?

Slide 100

Slide 100 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Let’s write reactive and reusable Integration Tests

Slide 101

Slide 101 text

class SearchFragment : Fragment , SearchView { ... override fun searchIntent() : Observable { return RxSearchView.queryTextChanges(searchView) } }

Slide 102

Slide 102 text

class SearchFragment : Fragment , SearchView { ... override fun render( viewState : SearchViewState) { if (viewState.loading) renderLoading() else if (viewState.result != null) renderResult(viewState.result) else if (viewState.error != null) renderError() else throw IllegalStateException("Unknown ViewState") } }

Slide 103

Slide 103 text

class SearchFragment : Fragment , SearchView { @Inject var viewBinding : SearchViewBinding override fun searchIntent() : Observable { return viewBinding.searchIntent() } override fun render( viewState : SearchViewState) { viewBinding.render(viewState) } }

Slide 104

Slide 104 text

class SearchViewBinding : SearchView { val rootView : ViewGroup override fun searchIntent() : Observable { return RxSearchView.queryTextChanges(searchView) } override fun render( viewState : SearchViewState) { if (viewState.loading) … } }

Slide 105

Slide 105 text

class TestSearchViewBinding : SearchViewBinding { override fun render( viewState : SearchViewState ) { super.render(viewState) } }

Slide 106

Slide 106 text

class TestSearchViewBinding : SearchViewBinding { var statesList : List val renderedStates : BehaviorSubject> override fun render( viewState : SearchViewState ) { super.render(viewState) statesList = statesList.copyAndAdd(viewState) renderedStates.onNext(statesList) } }

Slide 107

Slide 107 text

class TestSearchViewBinding : SearchViewBinding { var statesList : List val renderedStates : BehaviorSubject> override fun render( viewState : SearchViewState ) { super.render(viewState) statesList = statesList.copyAndAdd(viewState) renderedStates.onNext(statesList) Screenshot.snap(rootView).record() } } http://facebook.github.io/screenshot-tests-for-android

Slide 108

Slide 108 text

class SearchFragmentTest { @Rule val rule = ActivityTestRule()
 val viewBinding : TestSearchViewBinding @Test fun onTyping3CharsShowLoadingThenResults() { onView(withId(…).perform(typeText(“Camera“) val states = viewBinding.renderedStates.blockingFirst() val loading = SearchViewState(true, null, null) val results = SearchViewState(false, someProducts, null) val expectedStates = listOf(loading, results) assertEquals(expectedStates, states) } }

Slide 109

Slide 109 text

class SearchFragmentTest { @Rule val rule = ActivityTestRule()
 val viewBinding : TestSearchViewBinding @Test fun onTyping3CharsShowLoadingThenResults() { onView(withId(…).perform(typeText(“Camera“) val states = viewBinding.renderedStates.blockingFirst() val loading = SearchViewState(true, null, null) val results = SearchViewState(false, someProducts, null) val expectedStates = listOf(loading, results) assertEquals(expectedStates, states) } }

Slide 110

Slide 110 text

class SearchFragmentTest { @Rule val rule = ActivityTestRule()
 val viewBinding : TestSearchViewBinding @Test fun onTyping3CharsShowLoadingThenResults() { onView(withId(…).perform(typeText(“Camera“) val states = viewBinding.renderedStates.blockingFirst() val loading = SearchViewState(true, null, null) val results = SearchViewState(false, someProducts, null) val expectedStates = listOf(loading, results) assertEquals(expectedStates, states) } }

Slide 111

Slide 111 text

class SearchFragmentTest { @Rule val rule = ActivityTestRule()
 val viewBinding : TestSearchViewBinding @Test fun onTyping3CharsShowLoadingThenResults() { onView(withId(…).perform(typeText(“Camera“) val states = viewBinding.renderedStates.blockingFirst() val loading = SearchViewState(true, null, null) val results = SearchViewState(false, someProducts, null) val expectedStates = listOf(loading, results) assertEquals(expectedStates, states) } }

Slide 112

Slide 112 text

class SearchFragmentTest { @Rule val rule = ActivityTestRule()
 val viewBinding : TestSearchViewBinding @Test fun onTyping3CharsShowLoadingThenResults() { onView(withId(…).perform(typeText(“Camera“) val states = viewBinding.renderedStates.blockingFirst() val loading = SearchViewState(true, null, null) val results = SearchViewState(false, someProducts, null) val expectedStates = listOf(loading, results) assertEquals(expectedStates, states) } } INPUT OUTPUT ASSERT.

Slide 113

Slide 113 text

class Inputs (val viewBinding : TestSearchViewBinding) { fun writeIntoSearchBox( term : String) { onView(withId(…).perform(typeText(term) } }

Slide 114

Slide 114 text

class Output (val viewBinding : TestSearchViewBinding) { fun renderedStates() : List = viewBinding.renderedStates.blockingFirst() }

Slide 115

Slide 115 text

class Assertions (val inputs : Inputs, val output : Output) { fun loadThenShowResults() = Completable.fromCallable { inputs.writeIntoSearchBox(“Camera“) val states = output.renderedStates() val loading = SearchViewState(true, null, null) val results = SearchViewState(false, someProducts, null) val expectedStates = listOf(loading, results) assertEquals(expectedStates, states) } }

Slide 116

Slide 116 text

class SearchFragmentTest { @Rule val rule = ActivityTestRule()
 val viewBinding : TestSearchViewBinding @Test fun onTyping3CharsShowLoadingThenResults() { val assertions = Assertions ( Inputs(viewBinding) , Output(viewBinding) ) assertions.loadThenShowResults().awaitBlocking() } }

Slide 117

Slide 117 text

class FooAndBarTest { @Rule val rule = ActivityTestRule()
 val viewBinding : TestSearchViewBinding @Test fun fooAndBar() { val fooAssertions = FooAssertions (…) val barAssertions = BarAssertions (…) fooAssertions.something() .concatWith(barAssertions) .blockingAwait() } }

Slide 118

Slide 118 text

class SearchFragmentTest { @Rule val rule = ActivityTestRule()
 val viewBinding : TestSearchViewBinding @Test fun onTyping3CharsShowLoadingThenResults() { val assertions = Assertions ( Inputs(viewBinding) , Output(viewBinding) ) assertions.loadThenShowResults().awaitBlocking() } }

Slide 119

Slide 119 text

class JvmSearchViewTest { @Test fun onTyping3CharsShowLoadingThenResults() { val assertions = Assertions ( JvmInputs(realPresenter) , JvmOutput(realPresenter) ) assertions.loadThenShowResults().awaitBlocking() } }

Slide 120

Slide 120 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Why Unit Tests - Test code in isolation - Reliable (not flaky) - Run fast - Testing UI as part of an Integration Test is senseless, since View is dump

Slide 121

Slide 121 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Model-View-Intent - takes state management serious —> Solves & avoids a lot of problems - Unidirectional dataflow - State driven by business logic - Composable - Easy to test

Slide 122

Slide 122 text

MOBICONF.ORG | 5-6 OCTOBER 2017 #mobiconf2017 Hannes Dorfmann @sockeqwe www.hannesdorfmann.com [email protected]

Slide 123

Slide 123 text

& Q&A questions answers 112

Slide 124

Slide 124 text

THANK YOU! 113