diff --git a/src/test/java/com/hr/staff/StaffApiIntegrationTest.java b/src/test/java/com/hr/staff/StaffApiIntegrationTest.java index 92c4bd3..4cd2699 100644 --- a/src/test/java/com/hr/staff/StaffApiIntegrationTest.java +++ b/src/test/java/com/hr/staff/StaffApiIntegrationTest.java @@ -12,6 +12,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.transaction.annotation.Transactional; import java.util.Set; @@ -24,11 +25,15 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. /** * 员工管理模块端到端集成测试(H2 内存库 + MockMvc + JWT)。 + * + *
使用 @Transactional 让每个测试用例在独立事务中运行并在结束后回滚, + * 避免测试数据相互污染,从而保证用例可重复执行。
*/ @SpringBootTest @AutoConfigureMockMvc @ActiveProfiles("dev") @TestMethodOrder(MethodOrderer.MethodName.class) +@Transactional class StaffApiIntegrationTest { @Autowired