Claude should verify business code first when unit tests fail
Resolved 💬 3 comments Opened Dec 16, 2025 by Wubabalala Closed Dec 19, 2025
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When a unit test fails, Claude directly fixes the test code without first verifying whether the business code has the same vulnerability.
What Should Happen?
- First check the actual business code (PaymentService.generateOrderNo())
- Verify if business code has the same issue
- Found business code uses UUID - no issue exists
- Then align test code with business logic
Error Messages/Logs
Steps to Reproduce
- Have a test file with a helper method that generates IDs using only timestamp:
```java
// Test helper
order.setOrderNo("TEST_ORDER_" + System.currentTimeMillis());
- Run a test that calls this helper twice in quick succession (same millisecond), causing duplicate key error
- Ask Claude to run all unit tests
- Observe: Claude immediately adds AtomicLong counter to fix the test, without checking business code
- Expected: Claude should first check PaymentService.generateOrderNo() to see if business code has the same vulnerability
- Upon checking, Claude would find business code uses UUID - no issue exists:
// Business code (already safe)
return String.format("ORDER_%d_%d_%s",
System.currentTimeMillis(),
userId,
UUID.randomUUID().toString().substring(0, 8));
- Correct fix: Align test code with business logic (use UUID), not invent a different solution (AtomicLong)
Claude Model
Opus
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.0.70 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗