Debug and Fix Failing Unit Tests in Java
Bilt RewardsSoftware Engineer · Technical ScreenLast updated
This question evaluates proficiency in debugging and maintaining a Java codebase with failing unit tests, testing competencies in unit testing, fault isolation, reading test assertions and stack traces, and verifying regression-free fixes.
You receive a small Java project for a credit-card rewards service with three failing unit tests: calculatesTriplePointsForRestaurants, returnsUnknownWhenMerchantCodeMissing, and aggregatesDailyPointsCorrectly. Without adding new tests, make minimal, well-justified code changes in up to three files so that all tests pass. Walk through your debugging process: reproducing failures, reading assertions and stack traces, isolating defects, and verifying no regressions. Then implement fixes such as correcting a category check for 'Restaurant', handling null/empty merchantCode safely, and resolving an off-by-one error in daily aggregation. Finally, explain how you would prevent future regressions (e.g., edge-case tests, input validation, and code review checklist).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.