SpringBootTest如何使用
SpringBootTest如何测试?
1.@RunWith(SpringRunner.class):让自动注入的注解生效
2.其次是测试类要和该项目下的启动类的目录保持一致。
package com.wxy; import com.wxy.config; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest @RunWith(SpringRunner.class) public class Test1 { @Autowired private RabbitTemplate rabbitTemplate; @Test public void testSend(){ rabbitTemplate.convertAndSend(config.EXCHANGE_NAME,"ideal.ubs","hhhhhhhh"); } }