Spring Boot通过Junit实现单元测试过程解析

网友投稿 206 2022-12-16


Spring Boot通过Junit实现单元测试过程解析

这篇文章主要介绍了Spring Boot通过Junit实现单元测试过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

1.需要在pom.xml中引入spring-boot-starter-test

org.springframework.boot

spring-boot-starter-test

2.单元测试代码

两个关键的注解

@RunWith(SpringRunner.class)

@SpringBootTest

package com.niugang.test;

import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.boot.test.context.SpringBootTest;

import org.springframework.test.context.junit4.SpringRunner;

import com.niugang.entity.User;

import com.niugang.service.UserService;

@RunWith(SpringRunner.class)

@SpringBootTest

publicBtMzqh class TestUser {

@Resource

private UserService userService;

@Test

public void test1(){

List list = userService.queryList(null);

System.out.println("集合大小:"+list.size());

}

}


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Python自定义计算时间过滤器实现过程解析
下一篇:java8新特性之接口的static和default的使用
相关文章

 发表评论

暂时没有评论,来抢沙发吧~