To Reproduce
Consider generating unit tests for project spring-boot-testing with modified OrderService class.
@Service
public class OrderService {
@Autowired
private OrderRepository orderRepository;
private List<Order> baseOrders = new ArrayList<>();
public int getOrdersCount() { return orderRepository.findAll().size() + baseOrders.size(); }
}
Expected behavior
Happy pass test is generated with correct assertions.
Actual behavior
The following failing test is generated.
It fails because real number of items in collection is 3, not 6.
@Test
@DisplayName("getOrdersCount: OrderRepositoryFindAll -> return orderRepository.findAll().size() + baseOrders.size()")
public void testGetOrdersCount_ListSize() {
ArrayList arrayList1 = new ArrayList();
arrayList1.add(null);
arrayList1.add(null);
arrayList1.add(null);
(when(orderRepositoryMock.findAll())).thenReturn(arrayList1);
int actual = orderService.getOrdersCount();
assertEquals(6, actual);
}
To Reproduce
Consider generating unit tests for project
spring-boot-testingwith modifiedOrderServiceclass.Expected behavior
Happy pass test is generated with correct assertions.
Actual behavior
The following failing test is generated.
It fails because real number of items in collection is 3, not 6.