[英]How do I stub-out RabbitTemplate when using Spring Framework?
我正在嘗試創建一些集成測試,並且想對注入RabbitTemplate的構造函數進行存根處理。 最好的方法是什么? 這是當前應用程序服務構造函數的示例,並且進一步使用amqp變量來創建消息。 我想使用RabbitTemplate的不同存根來創建消息方案。
private AccountRepository accountRepository;
private UserRepository userRepository;
private RabbitTemplate amqp;
@Autowired
public IdentityApplicationServiceImpl(UserRepository userRepository, AccountRepository accountRepository,
RabbitTemplate aRabbitTemplate) {
this.userRepository = userRepository;
this.accountRepository = accountRepository;
this.amqp = aRabbitTemplate;
}
因此,對於userRepository,accountRepository和aRabbitTemplate,我想根據情況使用特定的存根。 如果可以將RabbitTemplate存根,那么任何提示都是很棒的。
是的,可以將其存根。
只需使用RabbitOperations
或AmqpTemplate
接口AmqpTemplate
。
一個好的方法是模擬它並存根要使用的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.