我在运行 Spring Boot 测试时遇到异常。我在我的模型之一的属性上使用 pg-uuid。
@org.hibernate.annotations.Type(type = "pg-uuid")
private UUID userUuid;
Run Code Online (Sandbox Code Playgroud)
当我的测试用例被忽略时,我的应用程序运行顺利,但是当我运行测试用例时,我收到此错误。
原因:java.lang.ClassNotFoundException:无法加载请求的类:pg-uuid
我的完整测试课:
@NoArgsConstructor
@RunWith(SpringRunner.class)
@WebMvcTest(AuthController.class)
public class AuthControllerTest {
@Autowired
MockMvc mockMvc;
@MockBean
UserDetailsService userDetailsService;
@org.junit.jupiter.api.BeforeEach
void setUp() {
List<User> mockUserList= new UsersUtil().getUserList();
}
@org.junit.jupiter.api.AfterEach
void tearDown() {
}
@Test
public void login() throws Exception {
User user = new User();
user.setEmail("abc@example.com");
user.setPassword("123456");
try {
LoginResponseBean loginResponseBean =userDetailsService.login(user);
assertThat(loginResponseBean!=null).isTrue();
assertThat(loginResponseBean.getJwtToken()!=null).isTrue();
}
catch(Exception e){
}
}
}
Run Code Online (Sandbox Code Playgroud)
异常的堆栈跟踪:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190) …Run Code Online (Sandbox Code Playgroud)