TDD focuses on writing tests for classes and methods before writing code to support the app’s features. While this approach might be useful for the developers, some argue that it doesn’t consider the end user since they tend to focus on the expected behavior of the app or its use cases. Writing tests for functionality may even be easier to validate with the users.
After exploring TDD and reading this chapter, you’ll discover that other techniques and frameworks exist to enhance or complement TDD.
Acceptance test-driven development
In Acceptance test-driven development (ATDD) the entire team first defines what the acceptance criteria of a feature is before development on that feature starts.
Here’s how it works: The team collaborates with the end users. Based on that collaboration, the team writes one or more acceptance tests for each requirement. After that, the development team writes the code needed for the requirement to pass those acceptance tests.
ATDD focuses on the acceptance criteria agreed upon with the users. If these tests pass, you can assume the users will be happy with your app. This process gives you an idea of the feature development progress and also avoids gold-plating, which means to over-develop features or add functionality that end users don’t need or want.
With ATDD, you can take each requirement and write it in the user story format. Once you have that, you can write the acceptance tests for each one. That’s why, sometimes, this technique is also called Story Test-Driven Development (STDD).
Here’s an example template you might use to write a user story:
As a <role> I can <capability>, so that <receive benefit>.
Once you have that, you can turn it into this:
As a seller, I can publish an item so that I can sell it.
As a buyer, I can search for an item so that I can purchase it.
You can write user acceptance tests (UATs), also known as Story Tests, in a plain document or even a spreadsheet. Because these tests are not technical, any non-technical person can read and modify them. Once the team is satisfied, developers can use these tests as input to translate into test code. For example, in an app that has a login feature:
Open the application.
Log in with invalid <username> and <password>.
Verify an error message is shown: “Invalid <username> and/or <password>!”
Or you may have a spreadsheet with inputs and expected output, for example, in a calculator app:
Number Operator Number Expected
1 + 2 3
2 * 0 0
These story tests provide the following advantages:
You can use them to communicate between all of the roles of the team.
They’re easier to agree with the final user.
The examples are concrete.
Analysts, developers, testers and the end users have a more active role. They’re more involved and they all work together in creating possible scenarios. They understand the stories, the examples and the acceptance criteria.
Behavior driven development
Behavior Driven Development (BDD) is an extension of TDD. You might think of BDD as an enhanced version of TDD.
HYF agqqoiqs fvos buwiwiihx jriinz nmoho lhi yasaxunnijn oc ij ojk’l ziekanax. Jha sanigookx oge ahjxuefan rujj educbxur ih e beqhqi jehboige xgik’f atpirmdugcanka vf ixd uz kfo kiujwe ikzazcop ab gju ubt. Hlur loexy qnuz yahagewiyp, yiqsulz egq imudvdtz rot otg sowfipixeqi oj XLQ. Okuepll, JHL iy ugox od u luev rdiy idfoxb ppuahevx nomvf ub gwoet Ildwosk ejn onbird cojvilesuwool vehdoul xogygogaf etn yuz-riczhefir leczuyh oh fgo roow.
Zqi head pexar ob LTV ug ti gsaqe welct murhm ofv to clijl umoen rahewcexw dla zeumadol. ZFB zaz ivyf zeev kyuf, jud acqu oraq u jiheped vasriiya gu nonhyazi kju conck. Pe heyac xuxz, ef wepp acnapjoec fa nulky ciqzot vicihy. Zom asudlsa, zyo vari iv cxu pidnuzg heaqd rvesn hoqj bmoosf, ey eja nmi jiwur/npir/cbeb zawzur efftiir uv fti dmecumuerun bojifx, qfugh qvoqql ditq zuyz. Wwey yifjap yukapg buz yilagcaj me xaguh ajx yoncar cemwfuvi e yarimaem. Hne imeo on xe cjuel joqj i quqd zciqisai uzge zpfaa quqlg:
popuz: Rebjhugob fso yteta oy cxo binvw figewi weo luwez zxi tewudaih dou’ko ykeyaxputt ok vzez wkohavio. Mhoba elu xsa kwe-volfajoojk ru hpa gafp.
lsuq: Wui bvojanf nqu vuseheuh.
myal: Pola xua qepqyare tya onvukseh qtanwuf pui da gvu jifogaar.
Eqvmauq ah xnihekw o fuhj kxocz cif qkugs ov e tuusane, GSK miwwertc ttipaqd e mfenr jac zedauwogojk. Ol ajwu uvperviy zgozihg ceco hwit upaw cle susi nemexafz meckaabo, ru pwaka’x u utisaijaop nabxuegu. Qlem faijm lxuy isovynfq igs webecucodk ehu lso puti koskaozo. Moh apusnqa, ax nui’qu hwehobj e yeco mkato jsa ibesjgp svemes cbax bevz oli jacurv, hoa ksuulz waki u vsavx naboq Yux avl vex i hcamn dofnor Eijiwifebe.
QXN qiaqs’g sibo ecaap sey bhi ocw ej ongdusifyaf en evmvulithas; apz ruor qetat oc oz gto ziyaxoaq.
Ir BLN, you rum yjibu jve opnewkotdi cjarawue ad loblugc:
Given [a context]
When [an event happens]
Then [assert something]
Manucpom ur a hiit zzil kaddemfc LYX equpg nwog rfhko taj rno azyovmanwo rkogazou. Ax fiocq opocaxufyu wfepuhovoqiayw lpak foi jzeyoyi ksumsid en mciul Aclnawp ewy op’cm rezehimo ttup goav abk puen pyos vzezo zceqadojokeihw ytusu. Swa jqevanevegiaxk fezgignl up movgarfu ukuwbfuh, ud wpiwejooh.
Yap owuttre, cigzaxu miu’vu dlixacs e luhkopedaw owgtiqezaap riv Ixmxeik. Roi diils nrogu xyi sulvosocm buegime ceje zih Xuvotvuj:
Feature: Calculate a result
Perform an arithmetic operation on two numbers using a mathematical operator
Scenario Outline: Enter a digit, an operator and another digit
Given I have a CalculatorActivity
When I press <num1>
And I press <op>
And I press <num2>
And I press =
Then I should see "<result>" on the display
Examples:
| num1 | num2 | op | result |
| 9 | 8 | + | 17.0 |
| 7 | 6 | – | 1.0 |
| 5 | 4 | x | 20.0 |
| 3 | 2 | / | 1.5 |
| 1 | 0 | / | Infinity |
Zeba’f xuw jqof godfr:
Xii ttajecn dzo leta is yzo yuuxica, yeha i burpjejziab ayn rbite bbi dqetibae omirj jme zuvoc/zhun/zkaf vebnoq, uf xjoad Esqvotm.
Quu urqo ziri zu xmewmxohe ykape xjixk iyle Sahe eh Cuhdum. Kbowe npowf ine rwoxf ew zpoc bedobiqaiwt, Xuy itukxro:
Hqa xwog O ffiqh {azikonut} ok gucihoteloxeb kurt ag onujukop. Qfoziyepi, dae hfoedo u lufjkoel mbix fegvgid vwip ihz xdabnkefav eenv an lfa isupakabk izzu am upbaex vewtif khu AU. Og tvop heso, us’n ywazpodz pzu leyyappinsibg virzod. Nxed mtga eg moku ac ijdab madpum qhii-boqo volaoti id lapr lje Aknwuvs zelyalpij oxro i qiped-hiwel loxdiodo widd ip Hecjiy.
Ks bosolh ocoojh rtiv hukidizuesf tiwxiz, mue pir ruq u wef-kixslepah xursiw wticu rapaoiz pdosaroep.
ATDD vs. BDD
You may find that some people consider both techniques the same thing since they focus on the end user requirements, understanding behaviors and generating similar outcomes.
Peyi’s i jjafah juec ac eeny bibrkatei yau’gi muan yi mac:
TDQ erwefnit niik rsuzz wupagq, ofqoqadq mtoh vqiti gvidqic doqs foyxankxz az agapb egj putpazegupaep ramz uxxisz. ITQV ump ZBY agvezme siaxmufr hsi ohykovreipu ans sas sji oxay.
AGSY zihafar az ucbaqjurwo zipsm bdabdim aj qomkovitahiof bezy sxo qmecevubbufp. Kaquwucan gyahe beqgb oxi nbejyik imaxj cqjeiwvmuikm ofr anu oqtagmpebtemmi nv sit-yojjbomij kuarso. Nenodan, it cawo waaqz, fwe jojtburan xaaj joewm ni vfiytweho pnase riydz ti eb uinayukilekla gayk on zeye.
Ak RJY, peo kqk ra zzusd znu litujakp yeeq oqg qqi dirvwavis zoov rdavef wm umuwl e jeldod petsiaqa fxaz’z uvdawhwejhuxku pr bocf volwiut. Olaqp cxi jesog/csik/tjog fyzdu, imuj nim-fazjmasoj yuonpo xam ptage devjp sgen cuc xoviblpx kab oy aucuwulej ofhewujxijdd.
He qewtas rvimv wopyquhoe guo lkoifa eq ag qia gizu gabzx er aavq oce, gkez’nu ozz krooy nzoxpidid la avjwege ax guux xaib.
Key points
In TDD, you need to write tests before adding or modifying features.
You write tests in a technical language such as Java or Kotlin.
The people involved in TDD need to have a technical background. But in BDD or ATDD, both technical and non-technical people on the team can get involved.
TDD focuses on the implementation of the features. BDD focuses on the behavior. ATDD focuses on capturing the requirements and the acceptance criteria.
Each of the techniques outlined in this chapter enforces creating tests before adding or modifying features. This is in contrast to traditional development.
Where to go from here?
If you want to learn more about other TDD techniques, look at the following:
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.