SpringBoot整合第三方技术的实现
玥骋 人气:0整合Junit
在Boot环境下如何进行单元测设
- 注解:@SpringBootTest
- 类型:测试类注解
- 位置:测试类上方
- 作用:设置JUnit加载的SpringBoot启动类
例:
@SpringBootTest(classes = Springboot07JunitApplication.class) class Springboot07TestApplicationTests {}
相关属性
classes:设置SpringBoot启动类
注:如果测试类在SpringBoot启动类的包或者子包中,可以省略启动类设置,也就是省略classes的设定。
import com.ityc.service.BookService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class Springboot07TestApplicationTests { @Autowired private BookService bookService; @Test public void testService() { bookService.save(); } }
SpringBoot整合MyBatis
serverTimezone=UTC一定记得设置时区,否则idea会爆连接数据库错误,让人以为是密码错了!!!
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/ssm_db?serverTimezone=UTC username: root password: lyc type: com.alibaba.druid.pool.DruidDataSource
@Mapper public interface BookDao { @Select("select * from tbl_book where id = #{id}") public Book getById(Integer id); }
测试
@SpringBootTest class Springboot08MybatisApplicationTests { @Autowired private BookDao bookDao; @Test void testGetById() { Book book = bookDao.getById(10); System.out.println(book); } }
加载全部内容