无法从application.properties中读取值以运行Mockito Juit测试

时间:2018-11-10 14:29:19

标签: java spring junit mockito

我有下面的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)
    }
}

0 个答案:

没有答案