记录Spring Boot 开发中的测试手段。
😍 添加 spring-boot-starter-test 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
spring-boot-starter-test 提供的依赖有 spring-boot-starter-logging, spring-boot, junit, mockito-core, hamcrest-library, spring-test。
-
JPA 测试
@RunWith(SpringRunner.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace = Replace.NONE)
public class JPATest {
Logger logger = LoggerFactory.getLogger(JPATest.class);
@Autowired
private Stu