Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between TDD and BDD in javascript context

I am not able to differentiate between TDD and BDD. Can some one give a simple example to illustrate the difference in javascript context using jasmine?

like image 614
Subhadeep Avatar asked May 02 '26 01:05

Subhadeep


2 Answers

TDD (Test-Driven Development) Process start with developing test for each one of feature. TDD process has some step to follow. Theses steps just continue as long as the developer has more features to add.

  • Writing a test
  • Run Tests
  • Refactor
  • Add Tests
  • See Tests Fail

Code example for TDD

suite('testName', function() {
  setup(function() {
    //create object (if need only)
  });
test('should Return Name', function (){
            //test function
        });

BDD (Behavior Driven Development) Can be read almost like a sentence and more focused on the features.

Code example for BDD

describe("send Name", function(){ 

   it("should Return Name",function(){ 
      expect(sendName()).toEqual('ABC'); 
   }); 

})

TDD vs BDD

There are some problems while preforming TDD

  • Where to start
  • how much need to test
  • understand why test fails

Solution for above problems is BDD

TDD describe how system works.

BDD descripe how end user use the system.

like image 151
Lakmi Avatar answered May 04 '26 13:05

Lakmi


TDD

This means writing the tests before developing the software, making the software fit the tests (Red-Green Refactoring). Usually completed by writing unit tests before creating the software.

BDD

This is not about testing. It is about conversations.

The development team will talk to the business about the requirements, gaining enough information to be able to write scenarios that make development of the software more aligned with the actual business needs. (Whether this is a Word document or a test, it doesn't matter).

The scenarios created should be understandable by the business, the development team and everyone in between using language that both agree on.

BDD and TDD can be complementary

I apologise for not giving an example in Jasmine, but I can tell you that tools like Cucumber will help you along the way in writing in a BDD style, and they can integrate with Jasmine, to make a business understandable front end and a developer understandable back end.

like image 30
KyleFairns Avatar answered May 04 '26 13:05

KyleFairns