SpringBoot整合第三方技术的实现

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

SpringBoot整合第三方技术的实现

玥骋   2023-03-20 我要评论

整合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);
   }

}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们