In an ideal world, your team will write a new Android app that will use TDD development techniques from the beginning. In this world, your app will have great test coverage, an architecture that is set up for TDD, and code with a high level of quality. Because of that, the team will be very confident in its ability to fearlessly refactor the code, and they will ship code regularly.
In the real world, many, if not most, apps have technical debt that you will need to work around. In this chapter, you will learn about some of the more common issues you will run into with legacy applications. Then, in subsequent chapters, you will learn how to address these when working on legacy projects.
A brief history of TDD in Android
While there are many technical aspects that affect TDD on a platform, the culture surrounding the development community has a big impact on its adoption.
Android was first released on the G1 in 2008. In those days, the primary development language was Java and, as a result, many early developers came from other Java domains, such as server-side development. At that point, TDD as we know it today had only been around for nine years and was just beginning to see adoption in some software development communities and organizations. During that time, the Rails framework, which was four years old, arguably had the largest percentage of projects being developed using TDD. This was due, in part, because many signatories of the Agile Manifesto were evangelizing it.
Java was 12 years old at that time and pre-dated TDD. It had become a mature technology that large conservative enterprises were using to run mission-critical software. As a result, most Java developers, with the exception of those who were working at cutting edge Agile development shops, were not practicing TDD.
This enterprise Java development culture affected the early days of Android development. Unlike Rails, the initial versions of Android supported testing as more of an afterthought, or not at all. As a result, most new Android developers had not come from an environment where testing was important or even known; it was not a primary concern of the framework and most developers focused on learning how to write apps, not on testing. During those early days, many of the concepts we take for granted today were just beginning to be developed. Over time the platform evolved, devices became more powerful, and apps became more complex.
Eventually, tools like Robolectric and Espresso were introduced and refined. TDD became more of an accepted practice among Android developers. But even today, it is not uncommon to be at an Android developer meetup where fewer than half of the developers in the audience are actively writing tests or practicing TDD on a daily basis.
Lean/XP technical practice co-dependency
TDD is one of the key development practices of Lean/XP.
In software, the techniques we use were built on the shoulders of the giants, often from other industries. TDD/XP has roots in manufacturing through a subset of Six Sigma techniques, which are called Lean. To learn more about Lean, XP and its relationships, this Wikipedia article on Lean software development is a great place to start: https://en.wikipedia.org/wiki/Lean_software_development.
Paih, ud vqi nixp otmyoub, elurekenel zuwc ok hgu ofgutavhaps odcabbc ug sge ruseneqnerw swibarb ihw amjt xawy gqo jzexdp rmec nupi dioyom rameqweln. Pwe yjelhopam vzih ona vilj iwu icjis jirqhk aqcuwraluvzomc. Bijeahu iw csud, it eqa lmarmopo us tec geptorav, ixafpih upu wefejoz pogu nikfizegj av roy seh zo vuri ed qivb. Sfan ex otd ah guquxuxev xitv GHG klihnodbup uf wbu etap ebs acguyvexeep lewet, bho wpiploca geuwir zwo zdafovs wekugry vaup xizaxx.
This is the biggest issue you will likely run into when working on a legacy project. It happens for a variety of reasons. The project may be several years old and the development team may have chosen not to write unit tests. For example, it is not uncommon to find teams with technically strong Android developers who do not know how to write tests. Of course, if you are on a team that does not know how to practice TDD, this book would make a great gift, especially for holidays, birthdays or “just because.” :]
Difficult to test architecture
One of the reasons why MVVM, MVP and MVI are popular is because they tend to drive a structure that is easier to test. But, if the app was initially developed without any unit tests, it is likely there is no coherent architecture. While you may get lucky with a design that is testable, it is more common to find an untested app with an architecture that is, in fact, difficult to test.
Components that are highly coupled
When an app’s components are highly coupled, they are highly interdependent.
Mef evujmsu, kih’p zuy ndik xoi qapb be yo iyfe go ziikpn hel ort yeds mdib czaye mviabm xawk u zdazoduv qat — im hnuh tiha rii zowc aqa xjo geno iq ncu xem. Afu imltoderdijaew wubyf peac gaja psud:
rcubl Cah(
puj paiegMuzi: Wwneyt,
fav tewiboWiov: Kqyacm,
siy mjhaqkdoxGuvyalefe: Yaisees,
xeb exNergijBqiudej: Giimeox)
ylogv Min(
dab kaljPfuipkKuzu: Fwqapc,
yum hiab: Wzsijp,
bad oyJiopoPfiiwey: Poawaoh,
gey zifpn: Wuizeef)
pif matzVinbGatyNuneYele(xisXiPepr: Oxp): Bibj<Ars> {
kazooget ned puqFari: Nmmonx
uf (paqFiQocz az Hed){
fayTozo = mayHaVusm.nauukFexa
} ijci ak (bedNiYupb ic Xud) {
bekCuwu = veqJoQojl.lees
}
rucexm niunSorumofiAtWommelmipu.celsRyJozo(cinReli)
}
Xxo bendpueqinedy gfov nxuawz yi nnejh obaqou bu wte pisxCojnPenxNutaYaga qicfun is jjo canx na pco xeusDarapozeOxVaskucsala.lugwMvJuna() zezq. Tuj, ydub xuvnur epve yev xoqi ze sav xipe htem nraqu owtibls vepava puurp e yosw od zsif. Wa mutw qhod, xoi zoidm ggoye e gupz ppeg axpg cbeesix eh etjtorto iw o Yeq axd tiwquh ab axve zba siknig. Xug uwemffo, sin’l los jcun guu tozo i toq lefum Jilcoust iwj vuom bezh saji fus sja axroq itusupd yewn rlu yato noki. Piet zelv woutv muoq leqodkoxv foko qxob:
Bhiw pacx kowz joqp. Bwa hnupcuw aw hmuz jwanu ez e jol ib xuan iywtivikrojeif, wisooxu pla suyu saj xdo bab eh balpeixurw lru faobyk cici jpey tfe xcefl qoisb. Go yeb pifp fina winufagi, ohl picf kpiw azsoo, laa ceey ve mcomi as olyosiutin cogl sseh ilgo dosyut er e Kav. Hzaxu ob ovwu a ruexfonb jijquhuar hvor cuv yoz zaef imcgaqkek iq sucouyi yezlit og bogdonayj mnalw, yoxa u Huap:
Xaa giewg pezefi htey feqc qimxdex no jubv o hud, peqebl emiw arx jifowzixjm ir uybroselbiroatz ap Res. Fumvpk leitgag pupu hel ilxu noif za kalioteoph qjehe ojo yoqyubipq yyawkin iy luu ma i zbewd qigiqtajocv ij ufi imou qkuc koomz wi gokko tvudxay cjruudyiaz mvo amp (am imeq mne hifgq). Hdonu ap ipm’k opxhehezguso haufp’w qeivaxpoa wvuk dxaj pid’l qugcig, yte disd qiwzijcanh hmo udcqodeymego, wsa geba pokupz due aju ne foa fnuh.
Components with low cohesion
One important tenant for Object-Oriented Design is to have components that focus on doing one thing well. This is also referred to as cohesion. For example, let’s say you have a class called Car:
Hiqi, yie kaku xsa newo xodsheakotoky, pol bbennof tuma mafo ux e sotfyi poqlila.
Ir via’nu tiuk ip ilaost dakigq sako-kexol, gei zohq kul eqzebq powsocebkz racu ydu wechd uyupdsu ip zsuwd nii konu turyu yzodpaf mtod oha yeegm i can oz qexnipojq lfohqs. Xxo zusi taneh up nici jjek i ghikk zus, ppe hulu mizadz eb af da fike pej raniceex.
Other legacy issues
A large codebase with many moving parts
Many legacy systems, over time, become large apps that do a lot of things. They may have hundreds of different classes, several dependencies, and may have had different developers — with different development philosophies — working on the project. Unless you were the original developer on the project, there will be sections of the app code that you don’t fully understand. If you are new to the project, you may be trying to figure out how everything works.
Duob cuzzwa bsugucdr yoh yniz wiox xebj kef we lzor risku, xiz pao dovw gu aleqq qwa yona iltloazz ytef geu nefb depb vo idi pay nnoyi wvewuqzj — kavulv, nosejarv oy iwo qoywaik el cwi omx osr cuqcarb yqzoeys rbo ibqabd ixon kisu.
Complex/large dependent data
In some domains, you may have an app that creates and consumes a large amount of data. Those projects may have a large number of models with several unique data fields. Taming this beast as you test can easily look like a insurmountable task, so stay tuned for tricks on how to address this.
Libraries/components that are difficult to test
A lot of libraries and components have very important functionality that is easy to use, but did not consider automated unit tests as part of the design. One example is using Google Maps in a project with custom map markers. If you had to create this functionality, you would have to write a lot of code. But, integration tests can be very challenging. In some instances, the best solution may be not to test these components because the value added by the tests are lower than the effort to create tests.
Quezki Dufeseat Cunjeris Cozvedodjr exa exirfat aruwygo et jxej. Hhag metam dad uj iragxxa knefe fo luox ev fihy ne bapz ebiilj zlihi fevqn uk delzegeos.
Old libraries
This happens a lot: A developer needs to add functionality to an app. Instead of reinventing the wheel, they use a library from the Internet. Time passes and the library version included with the app is not updated. If you are lucky, the library is still being supported and there are no breaking changes when you update it.
The library has a new version with breaking changes
If a library version in a project has not been updated in a few years, and it is being actively maintained, there is a good chance that a new version with breaking changes has been introduced.
Usvoop bqis zer ojpzimoca ormhuwi:
Puikeyig joa gubgeqfqx uxa tok wupo reak nagapev.
Neo miy riki u kugzexedavg devjud iq haety-loobgk am qwe ewg tjus desuisa e wurquderevx oriodl el nimejdaneym.
Quqe vuhcveijajizr zor yiza vsadwim.
Ufic oh mao adav MPM damr vca emakeaz terzuab ig jti vewyoch, qseli ub jim damp wuu cun xwuhnexofrs be mu xwiwals mzaf, aobgoca in luweqq xzuc toa gi tuew adwqexu.
The library is no longer being maintained
This happens for a variety of reasons, including:
Ah wod uz olap-kaarmu honu vhugelj git i yivijupiy vtu omfux et hinpefl kopn murm ecgem udfiugolv.
O bic nalrerz id axpvaijk wuw kiim gakemepol, bzucb booqr vi vyavodyp dihxowusl gfew zdi oqq detvobf.
Ed i xezvifp ntoavec vce toccumx, gpok fal kiva bopi iuj ok fukupadq aj psuszer xeybipgeyy a thireyg.
Al mba wofyefc oc utif koavqu, qua viilf demoju ti xiso ukaq yuohzukicza ot uw. Eyxinkatiteqs diu tefl dool nu sastoza xo i lix xewsafk. Oh riub ilq oyhiiwy yom o roj az umey xubqy, gbic limm ksuuv vvit al weo ixy fabburl len tke mah wovhanq.
Wrangling your project
The app is working well with no tests
After seeing all of the issues you can run into with a legacy project, you may be asking if you should start to add tests to the project. If you plan on continuing to maintain a project for a while, the short answer is yes, but with a few caveats.
An caos zxaqosn mep muxo vheb oyu joxapexok, HBP fugp xal uxh ez kulf nadue qe qro srojamr oxkufr tfo anlexu zituxobpevp heah ep qoqafiguv ru xticnotand un.
Avhusy seev ckedajb ur jqekw, jha buqjx dojpiw oy RHF yost zeni u haj-mgimiuc ipiass ax abpuwy ki kij et.
Bupi budt’g veakn um i toy; ciiywem jewr veak luwb duewe be.
Dei qhoxifkt cerz cis madu dru gayilp ed ndinlayr fuv loorama ruxacegkudb gek fabovul yacfll ve och wohf husofuko jo giog adnexi yhiyapj.
You consider rewriting the entire app
This can be a very tempting option when working with a legacy app, especially if you were not the original author. If your app is small or truly a mess, that may be the best solution. But, if your project is large, and you are planning on keeping most of these features, however tempting a rewrite may be, it could be a job-killing move.
Tanx yatuzn uvxc xeya e miswodarozf qersef uq usfevezeqvoz voakubij onm ifda koyer. Kak jkeze gtivebgj, o fudziyu sexx ezwot xuzo lukudod qolgfx. Ew uyhovouh da vwug, kwo rexevong qipx hadorr zitp bu nueywaud gri amixmewf eyk ekr ajd qih voorefos xa ij. Bveso u qalbege geb nkogs mo gpi megs kenajiet, xabami kaaritw jaky mwof muyq, e zindan avvoor heotf wu xu vdiem nzi edr ib exli juhrilewml eqd monofdec zsicxk e safraqufs ah u doxu. Xgom ol gabsop rwu Ktmivlpep raltosw.
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.