springboot 使用socket组件 时对其他方法进行单元测试踩过的坑

package org.atgpcm.system.service;

import org.atgpcm.system.domain.SysAppletsConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
* @Description:
* @Author: ldg
* @Date: 2020/12/10
 *
 *          <dependency>
*               <groupId>org.springframework.boot</groupId>
 * *             <artifactId>spring-boot-starter-test</artifactId>
 * *         </dependency>
 *
 *
 * 如果项目中引入了websocket
 * @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 *
 * 原因 用@SpringBootTest(classes= {Pcm*******Application.class})
 * 会报  Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not availabl 错
*/
@RunWith(SpringRunner.class)
//@SpringBootTest(classes= {PcmServiceAdminApplication.class})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SysFunctionServiceTest {

    @Autowired
    private SysFunctionService sysFunctionService;

    @Test
    public void getAppletsConfig() {
        SysAppletsConfig sysAppletsConfig = new SysAppletsConfig();
        sysAppletsConfig.setId(1);
        sysFunctionService.getAppletsConfig(sysAppletsConfig);
    }
}

 

posted @ 2020-12-10 20:03  理葵  阅读(224)  评论(0编辑  收藏  举报
希望写博是我人生坚持在做的事情之一。