All questions
Showing of 91What is unit testing and why is it important?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Unit testing tests individual components (functions, methods, classes) in isolation to verify they work correctly.
Importance:
- Early bug detection: Catches issues during development
- Documentation: Tests document expected behavior
- Refactoring confidence: Enables safe code changes
- Design improvement: Promotes modular, testable code
- Cost reduction: Fixing bugs early is cheaper
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are the characteristics of a good unit test?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Good unit tests follow the FIRST principles:
- Fast: Run quickly (milliseconds)
- Independent: Don't depend on other tests or external systems
- Repeatable: Produce consistent results
- Self-validating: Clear pass/fail result
- Timely: Written alongside production code
Additional characteristics:
- Readable: Clear names and structure
- Focused: Test one specific behavior
- Isolated: Use mocks/stubs for dependencies
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the difference between unit testing, integration testing, and end-to-end testing.
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
- Unit Testing: Tests individual components in isolation using mocks. Fast and focused.
- Integration Testing: Tests how components work together. Involves real dependencies like databases.
- End-to-End Testing: Tests complete user workflows through the entire system. Comprehensive but slow.
Test Pyramid: Many unit tests (fast, cheap) → Some integration tests → Few E2E tests (slow, expensive).
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the AAA pattern in unit testing?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
AAA stands for Arrange, Act, Assert - a common pattern for structuring unit tests:
- Arrange: Set up test data, mocks, and preconditions
- Act: Execute the method or function being tested
- Assert: Verify the expected outcome
test('calculateDiscount returns correct discount amount', () => {
// Arrange
const price = 100;
const discountPercent = 10;
// Act
const result = calculateDiscount(price, discountPercent);
// Assert
expect(result).toBe(10);
});
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How should unit tests be organized and named?
How do you test error conditions and exceptions?
What is code coverage and what are its different types?
What is dependency injection and how does it help with testing?
What is Test-Driven Development (TDD) and what are its core principles?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
TDD is a software development methodology where tests are written before the actual code. The core principles are:
- Test First: Write a failing test before writing any production code
- Minimal Code: Write only enough code to make the test pass
- Incremental Development: Build functionality in small, testable increments
- Continuous Refactoring: Improve code structure while maintaining functionality
TDD follows the Red-Green-Refactor cycle, ensuring code is thoroughly tested and well-designed from the start.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What's the difference between TDD and traditional testing approaches?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Traditional Testing:
- Code first, test later
- Tests verify existing functionality
- Often achieves lower test coverage
- Testing is seen as a separate phase
TDD: - Test first, code second
- Tests drive the design and implementation
- Achieves high test coverage naturally
- Testing is integrated into development
TDD treats tests as specifications and design tools, while traditional testing treats them as validation tools.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What types of tests are typically written in TDD?
What is Behavior-Driven Development (BDD) and how does it differ from Test-Driven Development (TDD)?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
BDD is a software development methodology that extends TDD by focusing on application behavior from the end user's perspective using natural language specifications.
Key Differences:
- TDD: Write test → Write code → Refactor (code-focused)
- BDD: Define behavior → Write scenarios → Implement step definitions → Write code (behavior-focused)
BDD Benefits:
- Uses "Given-When-Then" format readable by non-technical stakeholders
- Promotes collaboration between developers, testers, and business analysts
- Creates living documentation that stays current with implementation
- Focuses on user value rather than technical implementation
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the Three Amigos approach in BDD
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The Three Amigos is a collaborative approach involving three key perspectives:
Business Analyst/Product Owner:
- Defines business requirements and acceptance criteria
- Provides domain expertise and user perspective
- Ensures scenarios reflect actual business needs
Developer:
- Provides technical feasibility insights
- Identifies implementation challenges early
- Ensures scenarios are testable and clear
Tester:
- Ensures comprehensive scenario coverage
- Identifies edge cases and error conditions
- Brings quality assurance perspective
This collaboration during scenario workshops creates shared understanding and reduces miscommunication before development begins.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are the main benefits of implementing BDD?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Communication Benefits:
- Natural language scenarios bridge technical and business teams
- Shared vocabulary reduces misunderstandings
- Collaborative scenario definition improves requirements clarity
Documentation Benefits:
- Feature files serve as living documentation
- Always up-to-date with current system behavior
- Accessible to all stakeholders regardless of technical background
Quality Benefits:
- Behavior-focused testing leads to better test coverage
- Early validation reduces costly late-stage changes
- Automated scenarios provide rapid regression feedback
Process Benefits:
- Faster feedback loops through executable specifications
- Better requirement traceability from idea to implementation
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the Given-When-Then structure in BDD scenarios
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The Given-When-Then structure provides a consistent format for describing behavior:
Given: Sets up the initial context or preconditions
- Establishes the starting state
- Defines what exists before the action
When: Describes the action or event being tested
- Represents user actions or system events
- Should be a single, clear action
Then: Defines the expected outcome or result
- Describes what should happen
- Includes observable changes or responses
Example:
Scenario: User login with valid credentials
Given the user is on the login page
When the user enters valid username and password
Then the user should be redirected to the dashboard
This structure ensures scenarios follow logical flow and are easily understood by all stakeholders.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is Cucumber and how does it implement BDD?
What are popular BDD frameworks for different programming languages?
What is the difference between a test double, mock, stub, and spy?
Compare different JavaScript testing frameworks (Jest, Mocha, Jasmine).
What are parameterized tests and when would you use them?
What is test isolation and why is it important?
Explain the concept of test fixtures and setup/teardown methods.
When should you use mocks vs real dependencies?
How do you test code that depends on external APIs?
Explain the TDD cycle (Red-Green-Refactor).
What are the benefits and drawbacks of TDD?
How do you handle testing private methods?
What makes a unit test maintainable?
How do you test asynchronous code?
What are flaky tests and how do you prevent them?
What are the limitations of code coverage metrics?
How do you measure and improve test suite performance?
What are some common unit testing anti-patterns?
What is the testing pyramid vs testing trophy and when to use each?
How do you test React components effectively?
How do you handle external dependencies in TDD?
What is the difference between mocks and stubs?
How do you test private methods in TDD?
What is triangulation in TDD and when do you use it?
How do you approach testing error conditions and exceptions in TDD?
What is the FIRST principle for unit tests?
How do you handle testing asynchronous code in TDD?
How do you refactor safely in TDD?
What is the testing pyramid and how does it relate to TDD?
What is the difference between BDD and ATDD (Acceptance Test-Driven Development)?
How do you use Background steps in Gherkin?
Explain Scenario Outline and Examples in Gherkin
What are tags in Gherkin and how are they used?
How do you handle data tables in Gherkin scenarios?
What is the difference between Doc Strings and Data Tables?
Explain the role of Step Definitions in BDD frameworks
How do you integrate BDD tests with CI/CD pipelines?
What are the best practices for writing effective BDD scenarios?
How do you handle test data management in BDD?
How do you handle asynchronous operations in BDD tests?
What are Page Object Models and how do they relate to BDD?
How do you handle error scenarios and negative testing in BDD?
What is the difference between imperative and declarative scenarios?
How do you implement hooks in BDD frameworks?
Explain the concept of Living Documentation in BDD
How do you implement BDD for API testing?
What are the challenges of mocking and how do you overcome them?
What is property-based testing and when would you use it?
Explain mutation testing and its benefits.
How do you test legacy code that wasn't designed for testing?
What is contract testing and how does it relate to unit testing?
How do you handle testing in a microservices architecture?
How do you handle testing legacy code that wasn't built with TDD?
What are some common TDD anti-patterns and code smells?
How do you apply TDD to database-related code?
How do you handle TDD when working with third-party APIs?
What is outside-in vs inside-out TDD?
How do you measure the effectiveness of TDD in a project?
How do you handle TDD in a microservices architecture?
What role does TDD play in continuous integration and deployment?
How do you apply TDD to user interface development?
What are the challenges of implementing TDD in large teams?
How do you handle TDD when requirements are unclear or changing frequently?
How do you test complex algorithms or mathematical functions with TDD?
What is mutation testing and how does it relate to TDD?
How do you balance test coverage with development speed in TDD?
How do you introduce TDD to a team that has never practiced it?
What are some advanced TDD patterns and techniques?
How do you apply TDD when working with third-party libraries and frameworks?
How do you handle feature toggles and conditional behavior in BDD?
What are the challenges of implementing BDD and how do you overcome them?
How do you measure the effectiveness of BDD implementation?
How do you handle complex business rules and validations in BDD scenarios?
What is Specification by Example and how does it relate to BDD?
How do you handle microservices testing with BDD?
What are the considerations for BDD in agile and DevOps environments?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
Unit Testing & TDD cheatsheet
- Fundamentals01
- Key Concepts02
- Testing Patterns03
- Mocking & Stubbing04
- Test-Driven Development (TDD)05
- Best Practices06
- Common Anti-Patterns07
- Testing Frameworks08
- Advanced Topics09
- Critical Interview Topics10
- Quick Reference11
- Interview Success Strategies12
- + 6 more inside
81 of 91 Unit Testing & TDD answers are in Pro.
Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.
- Full answers + code
- AI explanations, simpler or deeper
- 1,000 AI credits / month
- Cancel anytime
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.