Legend: You have legacy (without tests) service which calculates order amount. You've hired separate testing team. They worked hard some months and wrote acceptance tests.
- Go to
legacy-codebranch. - Observe
src/main/java/ru/agilix/workshop/bddandtdd/DeliveryContollerandsrc/test/resources/deliver.feature. - Run
src/main/java/ru/agilix/workshop/bddandtdd/Application. - Open in a browser http://localhost:8080.
- Run
src/test/resources/deliver.feature.
class DeliveryControllerShould {
@ParameterizedTest
@CsvSource({
"Обычный, 999, 1249",
"Обычный, 1000, 1000",
"VIP, 999, 999",
"VIP, 2499, 2499",
"VIP, 2500, 2375"
})
void calculateDeliveryFee(String clientType, Integer cartAmount, Integer orderAmount) {
assertEquals(orderAmount, new DeliveryController().calculate(clientType, cartAmount));
}
}
- Add SpringTest:
@SpringBootTest(webEnvironment= WebEnvironment.RANDOM_PORT)
public class DeliveryServiceApprovalTest {
@Autowired
DeliveryController deliveryController;
@Test
void vipClientShouldNotPayForDelivery() {
assertEquals(Integer.valueOf(2499), deliveryController.calculate("VIP", 2499));
}
}- Add TDD
DeliveryServiceShouldand createDeliverService.
@Test
void addDeliveryFeeToOrderAmount() {
assertEquals(1249, deliveryService.calculate(999));
}
@Test
void NotAddDeliveryFeeToOrderAmountIfItIsEqualOrMoreThen1000() {
assertEquals(1000, deliveryService.calculate(1000));
}- Replace call in
DeliveryContoller - Extract interface of
DeliverService
