Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

TDD vs BDD vs DDD

Hello,

I'm trying to understand the differences between TDD, BDD and DDD.

Hmmm ... if I have to test that an admin can suspend a member's account.

public function an_admin_can_suspend_a_members_account()
{
	//
}

According to me this test is a TDD AND a BDD.

  • TDD is how I code : I write the test first and then I write the code to satisfy the test

  • BDD is how I write the test : I write the test to express a user's behavior

Can somebody confirm this ?

Or perhaps help me better understand the differences between both ?

Furthermore I'd like to understand what DDD is and for this one I don't have any idea except what I have read on the web and according to me there is no real difference between BDD and DDD.

Thanks a lot to help me understand the differences between TDD, BDD and DDD. And if you can give some quick example, it would be great.

Thanks a lot.

V

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

Hello,

You're on the right track in understanding the differences between TDD, BDD, and DDD. Let's clarify these concepts further:

TDD (Test-Driven Development): TDD is a software development approach where you write a test before you write just enough production code to fulfill that test and refactoring. The cycle is usually as follows:

  1. Write a test that defines a function or improvements of a function, which should fail initially (since the function isn't implemented yet).
  2. Write the minimum amount of code necessary to pass the test.
  3. Refactor the new code to acceptable standards.

Your example test method an_admin_can_suspend_a_members_account() is indeed following the TDD approach if you write this test before implementing the functionality.

BDD (Behavior-Driven Development): BDD extends TDD by writing tests in a natural language that non-programmers can read. BDD focuses on the behavioral aspect of the system rather than the implementation aspect. It's more about the collaboration and shared understanding between developers, QA, and non-technical stakeholders.

In BDD, you would write scenarios as follows:

Feature: Account suspension

  Scenario: Admin suspends a member's account
    Given an admin is logged in
    And a member's account is active
    When the admin suspends the member's account
    Then the member's account should be marked as suspended

This is a BDD-style test, which is more about the behavior of the application from the user's perspective.

DDD (Domain-Driven Design): DDD is not a testing strategy but a software design philosophy that focuses on modeling software to match a complex domain. It emphasizes collaboration between technical and non-technical team members to create a ubiquitous language for the project. DDD involves breaking down a domain into bounded contexts and defining explicit models within those contexts.

DDD would influence how you design the system to handle the suspension of a member's account. For example, you might have an Account aggregate with a method suspend() that would be called by an admin service.

Here's a very simplified example of what a DDD approach might look like in code:

class Account {
    public function suspend() {
        $this->status = 'suspended';
        // Additional logic for suspending the account
    }
}

class AdminService {
    public function suspendMemberAccount(Account $account) {
        $account->suspend();
        // Additional logic for the admin suspending the account
    }
}

In summary:

  • TDD is about writing tests before code.
  • BDD is about writing tests in a way that describes the behavior of the system.
  • DDD is about structuring your code and design based on the domain you are working with.

I hope this helps clarify the differences between TDD, BDD, and DDD.

1 like

Please or to participate in this conversation.