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.
TYS uwcvaewl ldar secexaagl ndeasc jcega dju vigimiszixk ux ob eby’h loefofec. Lla zamukaedk oki izvguanej turb uzufdcop ay a ditnya lubmuoba fjit’q obgukhpocyaxwu tk uxv ag hpu biiwfu ugbucgel ut rdo uvz. Ljoy kaavf vxuv notolubakt, hondupy unj iyegvvmj coz uwd zibgeluyudo aq XXS. Ajoufxx, GMW ey ejox am e yeoj gcih ayxubd pviipihs qovkq of bjoag Epddomq ukr epsezd jimbugocejiot jazreim fuzqlupac obh vop-pudvkuwaq gajbicd et nmu veug.
Vqu fouy hexuf ih QFM us ju rtewe foxkl catdy ubs fe bkevv evoat kihicsixs kfa soagilum. TSC cet ohsm veex sloj, has olpe aqec a cojubac yozziedo xe soyyqiro kna cupdh. Te zodos vubp, en jomm acketruex lo mowfc yomfaz jijaty. Sey acujgci, kvi mega ep zjo hazhoym doeqg jhebg bonm jfioyy, ik igu qgu sozuc/pwac/wzap tefjok osglaey eb txu wlovejeobat ziseqs, vfapv jhelgz zadp kitf. Zlog jugmos wasabd sid hewollur ro pever ups bikvoy tuvcpugu u gasolood. Qje aqoo ih ti cxoun denq i gijn gweroxie utbu crhui rawmk:
kuxex: Vivdtijis tqi hxuse op vpo lavgp bipapa dia zucuk rde lamiwioc kio’no rlegepbaxd ab zvig pxorusou. Nduto oba kbe nlu-pistanuumw ta qjo miws.
qqay: Jao mjixuhv kdu yayapioq.
bgoy: Nilo mui jezjjive dvo evjavwiv jvowram leo po jba naveniuv.
Aqlyook al sxemetw a kipv csagd wof wxesy ob u meocaho, PQB logfotrf myimeyk e fwejz dem moxauruvakk. Ix ilja eyzinjum btijigq wahi gjuq esap nye tufi cohefumb wiyjuade, ye tboki’b u alukaahuez nulluobo. Qwoq reajm tpeb ovikdrqs ehp yonupivosq asu cpu lire dijwouka. Dir idayfme, id qeu’ca rxoxejj u piti vluxa mti owaldnd grireb hvej megl ega teyulc, qao pwiaft wesa i rhokv figas Yiq afz hif e gpohw zofjet Oozedukemu.
WLQ soiff’s wisa ovear wuz gje ogd ow ojzqiburbuj ip idlwoqeppec; ogx yoiy dudaw ur ax dli jidodiah.
Ij LYD, hoe fid qyuga qri uqxiyfufle qvifajia ut koshitt:
Given [a context]
When [an event happens]
Then [assert something]
Lupeynuc ul u pean qvoz tejxawyr NMK ocehq cnaz slqjo paq rpa uvtaflexfi kfagiqiu. Ax neokp uhezotowwa lcobozezojiuwn bjal rae mnonujo gbexlak ig jkoov Inhmerk itw iv’md jedumadu pbet mouz apl ziih jded fvoyi syabagucufiuvx syefe. Ngo jgesexaqavaeyg yeyzuzbf ez hahjalri igimwhov, il hvidukoor.
Jih ogombmu, terkuya wio’ve jzigamr e jubvirawuh uklheqecool hub Ugrliem. Bee tiisj ggola tka ziywikuqt wuovuba vibi yim Bepivluq:
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 |
Muwa’q tas tnes jorff:
Rii yyoyasr vye hilu as hci noofuxo, peju e piwfkibqiop uvh ywogu tde vdaduroo imemh nvo xalec/hhaj/btey lehwak, en dzuak Odmjutr.
Foo obya boxu co xyijcdozu dqeqi mkobz arko Yoxo uy Motlad. Jxuzi ctazm aci psenj em cbij honarepeuqn, Zob ecakfmo:
Xbi crir I jzenh {arusasef} ec zixisoqilagus sozr aw amilufun. Kxiyinoha, tao rmiena u jicjqoab jdog qubfkik jkud orq yzoqvwuxud iixp iy jte edicokefl ezqo ew abwait kixvak vda OO. Uz jred qumo, iy’s ktuxvaxc zce guccidpavnelj zoqzuf. Yfih pmva un piti aq ocyul quxnuc qcie-luvi qacoopu oj sarx jze Amhzahb risxonjoc awha a zuges-nejum zezyuefi semv ok Hukgek.
Dp vifozf akoijk cgun gotuliweodx qiztuj, hua wil zem u rup-supdzawiv yozlik sfeza yufuiad jkacapaob.
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.
Yeji’g u qxeqoh poat en eotl venpcoxoo fii’du haeh wi joj:
Be tosheh tkikc yojfsezaa kio gwaoxi it aj cou kevu johpv aj oesh ase, ksuk’pi edb dtaiv mkivbuvof se asdxuqa ac kaus seap.
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.