亲宝软件园·资讯

展开

SpringBoot整合第三方技术的实现

玥骋 人气:0

整合Junit

在Boot环境下如何进行单元测设

例:

@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);
   }

}

加载全部内容

相关教程
猜你喜欢
用户评论