Can someone engligthen my mind in TDD and BDD?

Hi sitepoint people, can you please enlighten my mind about TDD and BDD,and how can i perform this TDD and BDD is this for client code or server code to use ?..I really don’t understand this Two on how to use the TDD and BDD.

Thank you in advance.

The general algorithm is:

  1. Write a function (no matter server or client side)
  2. Write another function (test) to check is your first function working as expected

for example, if you made a PHP function:

function summ($a, $b) { return $a+$b; }

you can then make a test for it:

function testSumm() { 
    return summ(5, 8) == 13;
}

and run that test each time you want to check your project:

if (!testSumm()) { echo "summ() is broken"; }

When you making any changes in your code you then run all tests and look for errors.

TDD, Test-Driven Development.

  1. While Developing:
    a. Write a Test.
    b. Write as little code as possible to make pass it.
  2. Refactor the code. Make sure all your tests pass.
  3. Remove \Alter irrelevant tests after refactoring.

Typemock-The Unit Testing Company, recommends to use AAA structure for TDD in their blog (whenever possible):
From Typemock blog:
Arrange - is where you state the state
Act - is where you execute the code you want to test
Assert - is where you make sure that the outcome of the Act fulfills you expectation.

BDD, Behavior-Driven Development which is, well, same as TDD
BDD emerged from TDD after developers focused on the implementation in the unit tests rather than on the behavior\specs.
one difference thought, While TDD is readable by programmers only, BDD tools make BDD tests very readable to all,
meaning that someone outside the R&D can write the tests and pass to the R&D for implementation.

In BDD you’ll find the following structure:
Given - the state.
When - the action.
Then - the outcome.

Summery:
Arrange = Given
Act = When
Assert = Then
TDD = BDD in a dress.

Thank you for the inputs :smile:

By the way is this also applicable to procedural code ? …What if I am going to test the variable which is being post then pass it to function,how do i create a test function for this ?

Thank you in advance.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.