测试类:
import com.wanmait.MqSender; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest public class TestMQ { @Autowired private MqSender mqSender; @Test public void hello(){ mqSender.send(); } }
测试类注解添加: @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
WebSocket是servlet容器所支持的,所以需要加载servlet容器,webEnvironment参数为springboot指定ApplicationContext类型。webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT表示内嵌的服务器将会在一个随机的端口启动。
0条评论
我要评论