Я использую Spring Boot 1.5.7. Я пытаюсь использовать @SpyBean в @SpringBootTest, но все еще получаю исключение NoUniqueBeanDefinitionException.
@MockBean в порядке с @SpringBootTest, @SpyBean происходит Вот код, который мы тестировали:
@RunWith (SpringRunner.class)
@SpringBootTest
public class CustomerServiceSpyTest {
@Autowired
private CustomerService customerService;
@MockBean (name = "customerOrderRepository")
private CustomerOrderRepository customerOrderRepository;
@SpyBean (name = "httpSession")
private HttpSession httpSession;
@Test
public void saveMyOrderProductCountInSession () throws Exception {
// given
Customer customer = new Customer ();
given (httpSession.getAttribute ("loginUser"))
.willReturn (customer);
CustomerOrder order = new CustomerOrder ();
order.addProduct (new Product ());
order.addProduct (new Product ());
given (customerOrderRepository.findAllByCustomer (customer))
.willReturn (Stream.of (order));
// when
customerService.saveMyOrderProductCountInSession ();
int count = (Integer) httpSession.getAttribute ("orderCount");
// then
assertThat (count, is (2));
}
}