說明
New code must have at least 80% line coverage. The quality gate evaluates coverage on the diff, not the entire codebase.
This ensures new and modified code is tested without requiring 100% coverage on legacy code.
為什麼重要
- Regression safety — untested code breaks silently
- Refactoring confidence — tests act as a safety net for changes
- Documentation — tests show how the code is meant to be used
Enforcement
Quality Gate: new_coverage >= 80%
正例
@SpringBootTest
class OrderServiceTest {
@Test
void shouldCreateOrder() {
var service = new OrderService(mockRepo);
var order = service.createOrder(new OrderRequest("item-1", 2));
assertThat(order.getStatus()).isEqualTo(OrderStatus.CREATED);
assertThat(order.getItems()).hasSize(1);
}
}
反例
@SpringBootTest
class OrderServiceTest {
@Test
void shouldCreateOrder() {
var service = new OrderService(mockRepo);
service.createOrder(new OrderRequest("item-1", 2));
// ❌ no assertions — test passes but proves nothing
}
}