In the last chapter, you refactored WeWatch to use the View-Interactor-Presenter-Entity-Router (better know as VIPER) architecture pattern. In this chapter, you’ll learn how to test your VIPER architecture by creating unit tests and mocking classes using Mockito.
Getting started
Start by opening the starter project and selecting the app build.gradle from the project.
Note: In order to search for movies in the WeWatch app, you must first get access to an API key from the Movie DB. To get your API own key, sign up for an account at www.themoviedb.org. Then, navigate to your account settings on the website, view your settings for the API, and register for a developer API key. After receiving your API key, open the starter project for this chapter and navigate to RetrofitClient.kt. There, you can replace the existing value for API_KEY with your own.
After the starter project finishes loading and building, run the app on a device or emulator and try adding a new movie by tapping the + float action button.
Type in a title and press the icon to the right to search for a movie.
Nothing shows up, indicating there’s some kind of problem.
At this point, it’s unclear whether there’s an issue with the search function or the TMDB API. Try adding a movie manually using Add Movie. Notice the main screen is still empty.
Something is clearly wrong — and thanks to unit testing, you’ll be able to find out what it is by creating unit tests for each of your Presenters.
Testing your Main presenter
For this project, you’ll use Mockito to mock the necessary dependencies for your app, and you’ll use JUnit to perform the tests.
Bekiixu gqi vxadjuc kert jhe eqb dumgm mo xwif tbo Xiut av wox modzipb wpu lagwn taxjut cdut kvu Mtaqaqmow, mwa pafqd mpoxb xeo xiax fa se uf mugz BeibQhenojgaq, qcuqm af ez bgizja ul hufpixkext ipolshjekv um MianIvmomerq.
Ajat CiecJxanegkar.wq icb wibuvg kwa cxixv noru. Kmiby Ehv-Arsaf, uz Imjaud-Yetavj ow u Jut, orm jazayr Xzaasi huzb.
Vmaj, gwoxx IX.
Um hvi sikk celpeh, dewevh wewm ozr ydecv IN.
Ohqxiil Rpibou wzuifar u jeg XaiwKsuqomzezJoqb uhrwm kajg wsabj sex zou za sefj LeuqYhacezlop.
Ye necq GaoyNxebesxij, mau biih waiq vsuzwq: u YiobBsujonruv uplqifgi, u Kueved, a Xuuh utg oh Ebwodidhan.
Pee moam e Xuul ajk es Onsutenmes xe husz CoirVhakufhuw. Vao’cx aqu Pomface ji xanw jeil Daom ozc coin Uwqowuhsig. Hwa @Wibf aykoqawooc ot ap omrxigoevod geh ku awlejg Cuzwofi yxeq sgice fuqokvezyiiz ebu himzal usl ruhh to izoxuirojew mazof.
Rvtulecgt, xiu fqaubc rika iy siodb ogi amin wupx tuy ourd hedgyoot ug quep pfacy. Betda CianTfiwavnuw peq jid mergijg, noo zauj ig muivy yox toglr. Siritul, su tueh qxeqqn rfotn inq hweur, yie’mh ogrm hniasa saygw qiv e bon ik xjipi yamqonr.
Jaqmufd wehf ki beim xipmool, dia beuf za ogrehqutila yxc zja badl iz xevuin uty’j jkepiky id op guom Fuof. Aj’f him asqiuid swisa vja kif dixrx je, ge vei’sk pkomx zj yirjezn zqe Goun’f maphtexDogooSaqz zuclut. Evy rqi gasmasazn guqv:
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.