Back to Tech Interviews

Unit Testing Interview Master

Curated 20+ questions covering unit testing principles, TDD, AAA structure, mocks vs stubs, and code coverage metrics.

Total: 20 QuestionsLearned: 0 / 20 (0%)
Difficulty Filters

Tools & Options
Showing 20 of 20 questions
Beginner
What is Unit Testing, and why is it important?

Unit Testing is a software testing method where the smallest testable parts of an application, called units (typically functions, methods, or classes), are individually and isolatedly scrutinized for proper operation. It is important because it catches bugs early, simplifies debugging, facilitates refactoring, and acts as living documentation.

Intermediate
Explain the F.I.R.S.T. principles of Unit Testing.

The F.I.R.S.T principles are:

1. Fast: Tests should run quickly so developers can run them frequently.

2. Independent: Tests must not depend on each other's execution order or state.

3. Repeatable: Tests must yield the same result in any environment (local, CI).

4. Self-Validating: Tests should have binary outcomes (pass or fail) with no manual interpretation.

5. Timely: Tests should ideally be written before or alongside the code (TDD).

Beginner
What is the AAA (Arrange-Act-Assert) pattern?

AAA is a structural pattern for writing readable unit tests:

1. Arrange: Set up the test requirements, initialize variables, and mock objects.

2. Act: Execute the unit function/method under test.

3. Assert: Verify that the output or state matches expectations.

// AAA example in Jest
test('adds 1 + 2 to equal 3', () => {
  // Arrange
  const a = 1;
  const b = 2;

  // Act
  const result = sum(a, b);

  // Assert
  expect(result).toBe(3);
});
Advanced
Explain the differences between Dummy, Mock, Stub, Spy, and Fake (Test Doubles).
Intermediate
What is Test-Driven Development (TDD), and what is the Red-Green-Refactor cycle?
Intermediate
What is Code Coverage, and what are its different metrics?
Beginner
Does 100% Code Coverage mean code is bug-free?
Beginner
What is the Testing Pyramid?
Beginner
What is the difference between a Unit Test and an Integration Test?
Advanced
What is Mutation Testing?
Intermediate
What is Mocking, and why should we avoid over-mocking?
Intermediate
Explain Behavior-Driven Development (BDD).
Beginner
What is regression testing?
Beginner
What is a test runner vs a test assertion library?
Intermediate
Explain Parameterized Tests.
Advanced
What is Hermetic testing?
Intermediate
How do you test private methods in a class?
Intermediate
What is a flaky test, and how do you resolve it?
Beginner
Explain code-first vs test-first development.
Scenario
How do you handle testing systems that depend on current system time?

Technical Interview Mastery Blueprint

Proven methodologies and frameworks to succeed in technical and architecture rounds.

1. The Engineering STAR Technique

When responding to architectural or situational questions, structure your answer using Situation, Technical Constraint, Action, and Measurable Result. Rather than jumping straight to syntax, articulate the business problem, why certain patterns (e.g. caching, queuing, immutability) were selected over alternatives, and what latency or throughput improvements were achieved.

2. Defending Architectural Trade-Offs

Senior interviewers evaluate how you weigh trade-offs. Always explain why you chose an approach: e.g., memory overhead vs CPU cycle speed, consistency vs availability (CAP theorem), or normalized schemas vs denormalized fast reads. Stating the drawbacks of your own proposal demonstrates maturity and production experience.

3. Clean Code & Edge-Case Proactivity

In live-coding rounds, communicate your thinking aloud before typing. State edge cases explicitly: null or undefined inputs, extreme boundary values, concurrency races, and network timeouts. Writing modular, well-named functions with deterministic unit tests separates junior candidates from staff-level engineers.

4. Antipatterns to Avoid

Avoid reciting memorized definitions without practical context. Never dismiss non-functional requirements such as security (CSRF, injection, token rotation), observability (logging, metrics), and accessibility (ARIA, semantic standards). Always ask clarifying scope questions before writing complex implementations.

Continuous learning: Practice daily, mark completed questions as learned, and revisit difficult concepts.Explore All Interview Tracks →

Explore Related Tools

Hand-picked utilities and calculators related to this tool.

Related Tools