0% found this document useful (0 votes)
5 views

Test Driven Development

TDD

Uploaded by

mufadhal.hafizh
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Test Driven Development

TDD

Uploaded by

mufadhal.hafizh
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

*Test-Driven Development(TDD)*

=Software development methodology that emphasizes writing tests before writing the
actual code to implement functionality

Key principle of TDD:


1. Write Tests First: Before writing any new code, write a test that defines a
piece of functionality or behavior you want the system to exhibit.
2. Run the Test: Run the test, which should fail initially because the
functionality you're testing hasn't been implemented yet.
3. Write the Code: Write the simplest possible code to make the test pass. This
could involve just enough code to meet the requirements defined by the test.
4. Refactor: After the test passes, refactor the code for clarity, efficiency, or
other improvements without changing its behavior. The test ensures that the
refactored code still works.
5. Repeat: Repeat the process for each new feature or functionality.

The TDD Cycle:


TDD is typically structured around a Red-Green-Refactor loop:
1. Red: Write a test that fails (because the functionality doesn't exist yet).
2. Green: Write the minimal code to make the test pass.
3. Refactor: Clean up the code without changing its behavior, while keeping the
test green (passing).

Benefits of TDD:
- Improved Code Quality
- Better Design
- Easier Refactoring
- Documentation
- Faster Debugging

Common TDD Practices


- Unit Testing
- Mocking/Stubbing
- Test Coverage

TDD Tools:
- JUnit (Java)
- RSpec (Ruby)
- Mocha and Jest (JavaScript)
- pytest (Python)
- NUnit (C#)

You might also like