LearnThatStack Ace your next interview
Part of Testing

Unit Testing & TDD.

Start free Change topic Change
Practice · Questions

All questions

Showing of 91
Beginner 17
01

What is unit testing and why is it important?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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
Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What are the characteristics of a good unit test?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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
Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

Explain the difference between unit testing, integration testing, and end-to-end testing.

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
  • 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).

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

What is the AAA pattern in unit testing?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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);
});
Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

How should unit tests be organized and named?

Part of Pro
06

How do you test error conditions and exceptions?

Part of Pro
07

What is code coverage and what are its different types?

Part of Pro
08

What is dependency injection and how does it help with testing?

Part of Pro
09

What is Test-Driven Development (TDD) and what are its core principles?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.
Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

10

What's the difference between TDD and traditional testing approaches?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.
Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

11

What types of tests are typically written in TDD?

Part of Pro
12

What is Behavior-Driven Development (BDD) and how does it differ from Test-Driven Development (TDD)?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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
Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

13

Explain the Three Amigos approach in BDD

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

14

What are the main benefits of implementing BDD?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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
Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

15

Explain the Given-When-Then structure in BDD scenarios

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

16

What is Cucumber and how does it implement BDD?

Part of Pro
17

What are popular BDD frameworks for different programming languages?

Part of Pro
Intermediate 44
18

What is the difference between a test double, mock, stub, and spy?

Part of Pro
19

Compare different JavaScript testing frameworks (Jest, Mocha, Jasmine).

Part of Pro
20

What are parameterized tests and when would you use them?

Part of Pro
21

What is test isolation and why is it important?

Part of Pro
22

Explain the concept of test fixtures and setup/teardown methods.

Part of Pro
23

When should you use mocks vs real dependencies?

Part of Pro
24

How do you test code that depends on external APIs?

Part of Pro
25

Explain the TDD cycle (Red-Green-Refactor).

Part of Pro
26

What are the benefits and drawbacks of TDD?

Part of Pro
27

How do you handle testing private methods?

Part of Pro
28

What makes a unit test maintainable?

Part of Pro
29

How do you test asynchronous code?

Part of Pro
30

What are flaky tests and how do you prevent them?

Part of Pro
31

What are the limitations of code coverage metrics?

Part of Pro
32

How do you measure and improve test suite performance?

Part of Pro
33

What are some common unit testing anti-patterns?

Part of Pro
34

What is the testing pyramid vs testing trophy and when to use each?

Part of Pro
35

How do you test React components effectively?

Part of Pro
36

How do you handle external dependencies in TDD?

Part of Pro
37

What is the difference between mocks and stubs?

Part of Pro
38

How do you test private methods in TDD?

Part of Pro
39

What is triangulation in TDD and when do you use it?

Part of Pro
40

How do you approach testing error conditions and exceptions in TDD?

Part of Pro
41

What is the FIRST principle for unit tests?

Part of Pro
42

How do you handle testing asynchronous code in TDD?

Part of Pro
43

How do you refactor safely in TDD?

Part of Pro
44

What is the testing pyramid and how does it relate to TDD?

Part of Pro
45

What is the difference between BDD and ATDD (Acceptance Test-Driven Development)?

Part of Pro
46

How do you use Background steps in Gherkin?

Part of Pro
47

Explain Scenario Outline and Examples in Gherkin

Part of Pro
48

What are tags in Gherkin and how are they used?

Part of Pro
49

How do you handle data tables in Gherkin scenarios?

Part of Pro
50

What is the difference between Doc Strings and Data Tables?

Part of Pro
51

Explain the role of Step Definitions in BDD frameworks

Part of Pro
52

How do you integrate BDD tests with CI/CD pipelines?

Part of Pro
53

What are the best practices for writing effective BDD scenarios?

Part of Pro
54

How do you handle test data management in BDD?

Part of Pro
55

How do you handle asynchronous operations in BDD tests?

Part of Pro
56

What are Page Object Models and how do they relate to BDD?

Part of Pro
57

How do you handle error scenarios and negative testing in BDD?

Part of Pro
58

What is the difference between imperative and declarative scenarios?

Part of Pro
59

How do you implement hooks in BDD frameworks?

Part of Pro
60

Explain the concept of Living Documentation in BDD

Part of Pro
61

How do you implement BDD for API testing?

Part of Pro
Expert 30
62

What are the challenges of mocking and how do you overcome them?

Part of Pro
63

What is property-based testing and when would you use it?

Part of Pro
64

Explain mutation testing and its benefits.

Part of Pro
65

How do you test legacy code that wasn't designed for testing?

Part of Pro
66

What is contract testing and how does it relate to unit testing?

Part of Pro
67

How do you handle testing in a microservices architecture?

Part of Pro
68

How do you handle testing legacy code that wasn't built with TDD?

Part of Pro
69

What are some common TDD anti-patterns and code smells?

Part of Pro
70

How do you apply TDD to database-related code?

Part of Pro
71

How do you handle TDD when working with third-party APIs?

Part of Pro
72

What is outside-in vs inside-out TDD?

Part of Pro
73

How do you measure the effectiveness of TDD in a project?

Part of Pro
74

How do you handle TDD in a microservices architecture?

Part of Pro
75

What role does TDD play in continuous integration and deployment?

Part of Pro
76

How do you apply TDD to user interface development?

Part of Pro
77

What are the challenges of implementing TDD in large teams?

Part of Pro
78

How do you handle TDD when requirements are unclear or changing frequently?

Part of Pro
79

How do you test complex algorithms or mathematical functions with TDD?

Part of Pro
80

What is mutation testing and how does it relate to TDD?

Part of Pro
81

How do you balance test coverage with development speed in TDD?

Part of Pro
82

How do you introduce TDD to a team that has never practiced it?

Part of Pro
83

What are some advanced TDD patterns and techniques?

Part of Pro
84

How do you apply TDD when working with third-party libraries and frameworks?

Part of Pro
85

How do you handle feature toggles and conditional behavior in BDD?

Part of Pro
86

What are the challenges of implementing BDD and how do you overcome them?

Part of Pro
87

How do you measure the effectiveness of BDD implementation?

Part of Pro
88

How do you handle complex business rules and validations in BDD scenarios?

Part of Pro
89

What is Specification by Example and how does it relate to BDD?

Part of Pro
90

How do you handle microservices testing with BDD?

Part of Pro
91

What are the considerations for BDD in agile and DevOps environments?

Part of Pro

No matches

Try a different filter or search term.

Know someone prepping for Unit Testing & TDD? Send them this set.
Pro · $10/mo

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.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git