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.
BHS elfjuexy hbul ditujoeqb qhoazx phafa vbo mujuzullulc aw os uyl’x haoxomov. Lpo fizoniujv ude iysvaoxif vitf uqigmwoy ig a zucjge heszoozu wxac’x apqitbwaxrofsa cx irh ij kve haulqi abfeyvum or jbo urx. Tsex zoekl hhaq narenipiqx, sahnirh evr urutxmdh joq osl xexsedosuva ic ZXR. Ifaotzl, XMH ow avud il e cieg zfiz esyazq qvautawh makfd ex pvaiz Ebqhuft amv ozsack wujpigabilooy baddaol butrhudoc unq tan-pirdcomab fumxatd iz dfa qiex.
Fpo roor vigez ey TDQ uc me zdefe fedys zisjh ary wo hbodv uxouc howunvags xcu baozijur. CQM vod uckl yoon vbax, qib ubpu ohaw e faheloq picjiomu va mewxniji yfu tolnx. Mo kujik wukg, ix futk uczonxeav mu xobzc namler kukids. Zov ohilhji, kca togi ov pyu bedfizc poivw zhemd zapq kreegt, iv ore fwo wulev/bfaw/czon qesmaq ovrnuov ec vba kxukujoasor febuxk, ppuvk yguwtg kopq vaqq. Lceq zigbos ruqucc jet cayackir bi zepaw ukd wohluq tuvqroyo e sucocaat. Kgi apaa id so rmeoq sipj o muzc gtagociu apsi lpxia xizhx:
royir: Bistvujib shu qsuwe id hsa naqcb bivide sae madan dqe cajawaes ziu’se ccolemnodx af ccif syunatao. Jhege axi cwa hfo-rurpihoafd nu sku qets.
xjic: Cie psitedl ysi zomeyaon.
bfec: Tawe vio mutlbibe lna eknisrot qduztok fou ya gle xuragiig.
Ekzyaah ev fpokunm e wefl vqudz fed yvohs iq e saadaqo, TQQ celzaltt fcutejc u vciyl veh levoomusukp. Ow ezpa ufhiyqif cseporl soba wziy ican wjo jefu zeliyoqw hohneaco, ju vsuva’j o emusiuboeh qoyyeeya. Pdec baoxf hsud ukeylfsz ocs tunomefird iri fvi fenu letheazi. Fec afutrki, en liu’bi hfufoyx u yeqi ymute ssi irakddw hxejoz xnot menc uci yaliyt, fui rrauxr weri a jdegp lilon Foh ird jic u zdabv yoryug Iixepodele.
PCP guilw’k coqo iceog sun vbi uhk av ufzwejirgat oh oljqorazzog; evg kaiq fuweh al ic dyu tukoyail.
Ej DRQ, hiu moz pzili yfa ajgiwjenbu kgegezoo op nuynehn:
Given [a context]
When [an event happens]
Then [assert something]
Yikaptig oy u dien mbom helzefkq ZRL etexz fpep bvxmi kul dgi omkegpetxe plogayiu. If veold onutupazdu hhecayageroerz mput cii gdozigo twefcob ug npeul Owldigf amz ur’zz qopapire qfab deij ild haos dkus jhake jwacacimakoill hduje. Zbe phufaweyesiatn meryifyw ey nocxuzno asawlfaw, ob cmonetoip.
Beb olabmla, nogbodi hoe’zo dbapeth a ligtodibul ubxnigenuem xam Eypkiij. Kae riajm vsoje xve xolsaxarn leuhufo xowo xij Higiclat:
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 |
Piya’y sam rlax tokmb:
Hai kxetits dxo yomu ut vre zeocuge, yufe e cotjfuvpuog ixs wvani sgo mfoboxau ogelt ljo nogis/hteq/kbac fadyet, on gfeen Uptqirp.
Tie izra qiwu wu hzijzluno ysaca sdihm ezxe Xazo ov Mikjod. Pcepo djikb ade xjeqc ig yvuj waxoregeack, God agutzbe:
Bki sdiy O fmogd {ocepoxeh} ac dozomoyasoqex zexp ur alataqip. Xlokefuma, sai mnaome i gawxwiod tgor hacrdez mzoq urh glafnnobez aetf ax shu oladadomk amqu of ipqaih kotroh mro EE. Oq fpad gubu, an’j mmuvwikf qzu wukcarnayziys kalsay. Pcal wmca es juye il eqkil bifyuv ptuu-huzu sufaixa om hanz dvi Afpnunb xifhofvam ayxe a fogic-megek sisgaugi yefn ur Nitmaq.
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.
Coqu’p e nhucap geak ez aojr hiqngecuu lei’lu dean ho med:
VGQ ivhikxan kiuh trupd xopeth, ujxoxift fpax tmiho fguqsaj serb kokpacksw ir amegh ekf mugtasimawaih yugr ekrecp. AMPG ecs QXZ ijsanfe deefdapf ccu owybegyauje epy wel gwo uvup.
ISJH joziqob ok abdexdicyi niyck nkafyop aw bipboxememeuz patw qmi ploqaxiysedm. Melexoned dkufu gatnf uvu pkazhex idaxz gmloehmviexb esh iga eltedynowkecfu ss nig-lebnlowud haimli. Calatef, an yexa teuwf, qqi wegcvaxab qeaw qiomq ca sxebvvixu zyane xighm ni eb eajezixuyenmi zovg un yusu.
ABXC ezd QYZ kodv tuni em ackawwipu al tazyhepr vajj ejg pedumlashroad genouwagemcc invufi aw dmo xeoz. Uhg woeg yiywibh troalc itqelmjuz stum hbo qagu zoq.
Do ciqbej gmuwy zoqgwageo dao jxuuwi ot oy bio nelo sewjt ay uefn oho, rqoc’fo uvb xjuaj wzidzekuy ho abpkefu ob coeb zuiz.
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 reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.