我有下面的junit嘲笑类
@RunWith(MockitoJunitRunner.class)
Class MyTest{
@Mock
pirvate JmsTemplate jmsTemplate;
@InjectMocks
private final ProductService productService= new ProductService();
@Test
public void sendItem(){
Item i = new Item();
i.name("xyz");
productService.send(i)
verfity(jmsTemplate).convertAndSend("product.test",i)
}
}
测试包下的resources文件夹具有
application.properties, contents of it are
spring.profiles.active=test
And application-test.properties has
queue.name=product.test
运行上述测试用例时,验证失败
Actual invocation has are different Wanted
queue is null.
运行测试用例时,测试用例不会从属性文件中选择队列名称
我的productService类如下
class ProductService{
@Autowired
JmsTemplate jmsTemplate;
@Value("${queue.name}")
private String queue;
public void send(Item i){
jmsTemplate.convertAndSend(queue,i)
}
}