# TDD and BDD

**URL:** <https://www.ruby-forum.com/t/tdd-and-bdd/149568>\
**Category:** Rails\
**Created:** [September 26, 2008, 11:14am UTC](https://www.ruby-forum.com/t/tdd-and-bdd/149568 "2008-09-26T11:14:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [September 26, 2008, 11:14am UTC](https://www.ruby-forum.com/t/tdd-and-bdd/149568/1 "2008-09-26T11:14:58Z")

</div>

Hi  
Could anybody please tell me what these?BehaviouralDrivenDevelopment  
and TestDrivenDevelopment ? what are their pros and cons? And which is  
preferred by rails?

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [September 26, 2008, 1:30pm UTC](https://www.ruby-forum.com/t/tdd-and-bdd/149568/2 "2008-09-26T13:30:30Z")

</div>

Sijo Kg wrote:

> ```
> Could anybody please tell me what these?BehaviouralDrivenDevelopment
> 
> ```
> 
> and TestDrivenDevelopment ? what are their pros and cons?

TDD means you never write new lines of code until you have a failing  
test case  
that expects the code to exist.

A test case follows the Assemble Activate Assert pattern.

```
def test_case
  a = assemble()
  q = a.activate(41)
  assert{ q == 42 }
end

```

All TestCases first Assemble the data resources they intend to use.

Then they Activate a target method. (Preferrably the one you name your  
real test  
case after!)

Then they Assert that some side-effect, from that method, is within  
tolerance.

You write one of those first, get it to fail for the correct reason, and  
only  
then write new production code to pass the test. Repeating this in tiny  
cycles  
helps you avoid endless debugging.

Behavior Driven Development is TDD reinvented to use a literate  
framework. By  
“literate” I mean you try to use the verbiage that your client uses when  
expressing your business rules as requirements and specifications. So  
the AAA  
pattern becomes:

specify ‘the assembled activator adds 1 to its input’ do  
a = assemble()  
q = a.activate(41)  
q.should.equal 42  
end

After that grammatical transformation, most of the concepts are the  
same. When  
you BDD-first, and write failing specs before passing them with new  
code, you  
are essentially doing TDD.

> And which is  
> preferred by rails?

Either. All projects should have tests (or specs), but Rails makes them  
easier  
than some systems we could mention because Rails was invented using TDD.  
And BDD  
specs can use the same “mock objects” as the TDD to write the same kinds  
of tests.

BDD has a slight “con”, compared to TDD, because you need tons of extra  
verbiage  
(.should, .should\_not, etc.) to get anything done. The BDD system (such  
as  
test/spec) will provide them, but you must still use them, and they  
don’t look  
very programmerly. BDD is for high-level tests.

TDD has a slight “con” over BDD, because you cannot easily nest test  
cases, so  
each one tests a variation of the other. BDD does that very well. TDD is  
for  
low-level tests.

Neither have any “con” over the alternative - Code And Fix. No project  
should  
ever not have unit tests, and I can think of a project that should not  
use  
test-first.

–  
Phlip

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [September 26, 2008, 2:14pm UTC](https://www.ruby-forum.com/t/tdd-and-bdd/149568/3 "2008-09-26T14:14:54Z")

</div>

Hi  
Thanks for your reply  
Sijo
