Skip to content
tezvyn:

Testing

242 bites tagged Testing — interview questions with model answers, and 60-second explainers.

React & Next.js2 min read

How do you unit test a custom React hook like useCounter?

This tests whether you know hooks must run inside a component and that renderHook provides that scaffold. A strong answer names renderHook and act, explains result.current access, and warns against calling hooks directly.

React & Next.js2 min read

How does React Testing Library's guiding principle influence query choice?

This tests whether you prioritize user-visible attributes over implementation details when selecting queries. A strong answer ranks getByRole, label, and text above testId because users interact with meaning, not data attributes.

Python & FastAPI2 min read

How do router-level and app-level dependencies affect dependency override testing?

This tests FastAPI dependency hierarchy and test isolation. A strong answer states overrides are global to the app, so router-specific deps need scoped fixtures to prevent cross-test leaks. A red flag is claiming APIRouter has its own override registry.

Python & FastAPI2 min read

How do you test a FastAPI WebSocket endpoint and lifecycle with pytest?

Tests knowledge of FastAPI TestClient usage for async WebSocket lifecycles. Use a with statement for websocket_connect; assert send, receive_json, and close; tests use standard def because TestClient handles the async app.

Python & FastAPI2 min read

How do you test FastAPI background tasks are enqueued correctly?

This tests mocking framework hooks without firing side effects. A great answer: mock BackgroundTasks or override its dependency, assert add_task got the right function and payload, and test the sender separately.

Python & FastAPI2 min read

How would you use pytest fixtures to manage TestClient and mock dependencies?

Tests FastAPI test isolation and dependency overrides. Strong answer: function-scoped fixture yielding TestClient, mock injection via app.dependency_overrides, and teardown cleanup to prevent state leaks.

Python & FastAPI2 min read

How do you test a FastAPI endpoint without real tokens?

Tests whether you know FastAPI's dependency override mechanism to isolate business logic from auth. A great answer describes using app.dependency_overrides to swap the auth Depends for a mock returning a fake user, then cleaning up after the test.

Python & FastAPI2 min read

Explain FastAPI dependency overrides with an in-memory SQLite test example

This tests FastAPI's hook for swapping dependencies cleanly in tests. A strong answer names app.dependency_overrides, defines a test-only in-memory SQLite session, and handles teardown. A red flag is patching globals or mocking ORM instead of dependency.

Python & FastAPI2 min read

What is FastAPI's TestClient and how does it differ from requests?

Tests if you know TestClient runs pytest against the app directly without a live server. Good answers note its HTTPX-based Requests-like API, passing the FastAPI app into the client, and simple asserts. Red flag: saying you need a running server and real URLs.

Python & FastAPI2 min read

How do you test a FastAPI GET endpoint with pytest and TestClient?

Import TestClient and app, write a test_ function, call client.get("/items/1"), assert status_code == 200 and json() matches expected data. FastAPI testing with TestClient. Using requests or forgetting test_ prefix.

Python & FastAPI2 min read

Override a FastAPI dependency at the APIRouter level

Tests FastAPI DI scoping limits. Answer: APIRouter has no dependency_overrides; create a sub-app, apply overrides, mount it. Red flag: Claiming router-level overrides exist or mutating global app state.

Python & FastAPI2 min read

How would you override a FastAPI dependency during testing?

Tests your grasp of FastAPI's dependency override mechanism. A strong answer mentions app.dependency_overrides, notes that sub-dependencies are bypassed, and stresses clearing overrides after each test.

Python & FastAPI2 min read

Testing FastAPI Lifespan Events

FastAPI lifespan events only run when TestClient is used as a context manager. Use this to test startup logic like DB pools before endpoints. Using TestClient(app) without with skips lifespan, leaving your app uninitialized and tests silently wrong.

MLOps & Infrastructure2 min read

Design a robust automated testing strategy for ML models before production

Statistical offline thresholds, shadow-canary launches, input drift detection, and rollbacks tied to KPIs. Validating probabilistic systems beyond binary pass-fail.

Go & Rust2 min read

Explain fuzz testing and set up a basic fuzz test

This tests coverage-guided fuzzing and toolchain wiring. Strong answer: defines fuzzing as automated input mutation driven by code coverage, contrasts it with hand-written examples, and sketches Go's FuzzXxx or Rust's cargo-fuzz setup.

Go & Rust2 min read

How do you use ResetTimer, StopTimer, and RunParallel in Go benchmarks?

Tests Go benchmark timer hygiene and parallel execution. A strong answer covers b.StopTimer before setup, b.ResetTimer before the loop, and b.RunParallel for CPU-bound scaling. A red flag is resetting without stopping or using parallel benchmarks for I/O.

Go & Rust2 min read

What is go test -race and when is it crucial?

This tests knowledge of Go's race detector. A strong answer says -race instruments code to detect racy reads/writes, finds data races not deadlocks, and is crucial for concurrent apps under load.

Go & Rust2 min read

How does Rust differentiate unit and integration tests?

Tests Rust test layout and privacy. Unit tests sit in src/ under #[cfg(test)] and call private functions via super::. Integration tests go in tests/ as external crates. Wrong: claiming it blocks private testing or merging them into src/.

Go & Rust2 min read

How do you write a table-driven test in Go?

Tests idiomatic Go test design. A strong answer: slice/map of structs with inputs/expected outputs, loop with t.Run for named subtests, and cite DRY code, parallelization, and failure isolation. Red flag: separate Test functions per case or omitting t.Run.

Go & Rust2 min read

How does cargo differentiate unit and integration tests by location?

This tests Rust test layout conventions. Unit tests live inside src files in cfg(test) modules; integration tests go in top-level tests/ files as separate crates. Red flag: saying integration tests need cfg(test) or can use private APIs.

Go & Rust2 min read

What Go tool detects data races and how do you invoke it?

This tests Go's built-in race detector. A strong answer names the -race flag, notes it instruments memory accesses to catch concurrent unsynchronized reads/writes, and shows go test -race. A red flag is confusing it with static analysis or external tools.

Flutter & Dart2 min read

How do you test Flutter platform channels and mock native responses?

Tests MethodChannel mocking in widget tests. Strong answers intercept calls via TestDefaultBinaryMessengerBinding, encode replies with StandardMessageCodec, pump the widget, and assert UI state.

Flutter & Dart2 min read

Set up an integration test for a multi-screen login flow

This tests your grasp of integration_test's device runtime versus headless widget tests. A strong answer covers the integration_test directory, ensureInitialized, driving a login flow end-to-end on device.

Flutter & Dart2 min read

Unit test a BLoC handling an AddItem event and emitting state

Use blocTest with build, act, expect; mention seed, skip, and mocktail for dependencies. Whether you know BLoC testing idioms and why bloc_test beats manual assertions.

Get Testing bites daily.

Five a day, five minutes, offline. With quizzes so it sticks.

Open testing — you’ll join as an early tester.