1 Star 0 Fork 0

魔芋红茶 / learn_spring_boot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
StudentServiceTests.java 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
魔芋红茶 提交于 2023-06-25 18:09 . ch48
package com.example.jpa;
import com.example.jpa.models.user.Student;
import com.example.jpa.repositories.user.StudentRepository;
import com.example.jpa.services.user.StudentService;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import java.time.LocalDate;
import java.util.List;
/**
* Created with IntelliJ IDEA.
*
* @author : 魔芋红茶
* @version : 1.0
* @Project : jpa
* @Package : com.example.jpa
* @ClassName : .java
* @createTime : 2023/6/25 12:43
* @Email : icexmoon@qq.com
* @Website : https://icexmoon.cn
* @Description :
*/
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@SpringJUnitWebConfig(classes = {JpaApplication.class})
@TestPropertySource("classpath:application.properties")
public class StudentServiceTests {
@Autowired
private StudentService studentService;
@Autowired
private StudentRepository studentRepository;
private List<Student> students = List.of(
new Student("icexmoon", LocalDate.of(1989, 10, 1), Gender.MALE),
new Student("JackChen", LocalDate.of(1990, 5, 1), Gender.MALE),
new Student("HanMeimei", LocalDate.of(1991, 6, 1), Gender.FEMALE));
@BeforeEach
void beforeEach() {
studentRepository.deleteAll();
for(var student: students){
studentRepository.save(student);
}
}
@Test
void testList() {
List<Student> students = studentService.list();
Assertions.assertEquals(this.students, students);
}
@AfterEach
void afterEach(){
studentRepository.deleteAll();
}
}
Java
1
https://gitee.com/icexmoon/learn_spring_boot.git
git@gitee.com:icexmoon/learn_spring_boot.git
icexmoon
learn_spring_boot
learn_spring_boot
main

搜索帮助