数据层测试事务回滚
Transactional注解
测试用例设置随机数据
模拟案例
编写application.yml
编写测试实体类
package com.taotao.testcase.domain;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* create by 刘鸿涛
* 2022/5/22 17:02
*/
@SuppressWarnings({"all"})
@Component
@Data
@ConfigurationProperties(prefix = "testcase.user")
public class UserCase {
private int id;
private String name;
private int password;
private String gender;
private String addr;
}
编写测试类
SpringbootTest注解,以及自动装配
package com.taotao.testcase.testMain;
import com.taotao.testcase.domain.UserCase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
/**
* create by 刘鸿涛
* 2022/5/22 17:08
*/
@SuppressWarnings({"all"})
@SpringBootTest
public class Test {
@Autowired
private UserCase userCase;
@org.junit.jupiter.api.Test
public void test(){
System.out.println(userCase);
}
}