spring boot 单元测试

单元测试,在开发中用于测试我们方法或服务的正确性,一般写在工程test包下。

@RunWith(SpringRunner.class)  
@SpringBootTest(classes = Application.class)    //表示为spring boot测试
public class AtrributeDataMapperTest {
    private static final Logger logger = LogManager.getLogger(AtrributeDataMapperTest.class);

    @Autowired
    private AtrributeDataMapper mappper; //注入需要测试的类

    @Test
    public void testGetColumnValues_Level3_Cable() {

        Integer instanceId = 2230;
        String tableName = "t_cable";
        Integer level = 3;
        String field = "Length";
        List<Object> data = mappper.getColumnValues(instanceId, tableName, level, field);
        data.forEach(System.out::println);
    }
}

注意:@SpringBootTest的classes属性指定springboot的启动类的class,如这里的Application.class
    如果不加classes属性,那么当前测试类必须在启动类所在的包或其子包中。否则运行时异常

 

posted @ 2019-03-21 20:36  foreast  阅读(206)  评论(0编辑  收藏  举报