PrepPilotPractise free

Software Testing interview questions

Unit, integration, E2E, mocks, TDD and test design

17 questions · assert · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

What is the test pyramid and why is it important?

The test pyramid is a strategy that suggests having many unit tests, fewer integration tests, and even fewer end-to-end tests. It's important because it helps maintain fast, reliable, and maintainable test suites by balancing coverage and cost.

How do you structure a unit test?

I use the Arrange-Act-Assert pattern: first, I set up any necessary data or mocks, then I execute the function under test, and finally I assert that the result matches the expected outcome.

Why should unit tests be isolated?

Unit tests should be isolated so they don't depend on external systems or shared state. This ensures they run quickly and consistently, making it easier to pinpoint failures.

What is a mock and when would you use it?

A mock is an object that simulates the behavior of real dependencies and allows you to verify interactions. I use mocks when I need to check if a function calls another service or method as expected.

Intermediate questions

Explain the difference between a stub and a fake.

A stub provides predefined responses to method calls, while a fake is a simplified implementation that mimics the real dependency. Fakes are useful for testing logic with lightweight substitutes, whereas stubs are mainly for controlling outputs.

How do you use Testcontainers for integration testing?

I use Testcontainers to spin up real database containers during integration tests. This lets me test against actual database behavior without affecting production or development environments, and ensures clean setup and teardown.

What causes flakiness in end-to-end tests and how do you address it?

Flakiness often comes from timing issues, network instability, or reliance on external systems. I address it by controlling test data, minimizing dependencies, and using retries only when necessary to avoid masking real issues.

Describe the TDD workflow.

TDD involves writing a failing test first, then implementing code to pass the test, and finally refactoring the code and tests for clarity and maintainability. This cycle helps ensure code is well-tested from the start.

What does code coverage tell you about your tests?

Code coverage shows how much of your code is executed by tests. It's useful for spotting untested areas, but high coverage doesn't guarantee correctness or meaningful assertions.

How does contract testing help in microservices?

Contract testing verifies that services adhere to agreed interfaces, catching mismatches before deployment. This prevents integration bugs and ensures smooth communication between microservices.

How do you safely add tests to legacy code?

I start by writing characterization tests to capture the current behavior of legacy code. This lets me refactor or add new tests without risking breaking existing functionality.

How do you decide when to use a mock versus a spy?

I use mocks when I need to simulate behavior and verify interactions, and spies when I want to record how functions are called without changing their behavior. The choice depends on whether I need to control outputs or just observe calls.

Senior questions

How would you design a test suite for a large microservice system?

See the answer in the app, free

What are the trade-offs between unit, integration, and E2E tests?

See the answer in the app, free

How do you handle flaky tests in CI/CD pipelines?

See the answer in the app, free

How would you improve test coverage in a legacy codebase without breaking production?

See the answer in the app, free

What are the limitations of TDD and how do you adapt your approach?

See the answer in the app, free

More Developer fundamentals topics