我遇到了Jhipster的测试包。我想知道我是否可以禁用它们,即使我知道修复它们也更好。
无论如何,我告诉你我的问题,我希望能得到一些帮助来解决这个问题。
我刚刚编写了一个Jhipster webapp代码。我使用main()
类在测试模式下运行应用程序。一切似乎都很完美,但是当我尝试构建它时,我得到了12次失败的测试和1次错误。
堆栈跟踪:
Failed tests:
DeskResourceIntTest.createDesk:113 Status expected:<201> but was:<500>
DeskResourceIntTest.deleteDesk:234 Status expected:<200> but was:<500>
DeskResourceIntTest.updateDesk:196 Status expected:<200> but was:<500>
DeskResourceIntTest.updateNonExistingDesk:217 Status expected:<201> but was:<500>
EventResourceIntTest.createEvent:111 Status expected:<201> but was:<500>
EventResourceIntTest.deleteEvent:238 Status expected:<200> but was:<500>
EventResourceIntTest.updateEvent:199 Status expected:<200> but was:<500>
EventResourceIntTest.updateNonExistingEvent:221 Status expected:<201> but was:<500>
UserResourceIntTest.createUser:170 Status expected:<201> but was:<500>
UserResourceIntTest.deleteUser:521 Status expected:<200> but was:<500>
UserResourceIntTest.updateUser:365 Status expected:<200> but was:<500>
UserResourceIntTest.updateUserLogin:409 Status expected:<200> but was:<500>
Tests in error:
CustomUserResourceIntTest.initializationError » Test class should have exactl...
Tests run: 146, Failures: 12, Errors: 1, Skipped: 0
我显然编辑了jhipster生成的类,但此时我不知道如何修复这些问题以最终构建和完成我的应用程序。
此代码行中的所有失败测试均失败:
restUserMockMvc.perform(put("/api/users")
.contentType(TestUtil.APPLICATION_JSON_UTF8)
.content(TestUtil.convertObjectToJsonBytes(managedUserVM)))
.andExpect(status().isOk());
这是12次失败测试的情况,抛出错误的方法是.andExpect()
。
我在这种模式下编辑了CustomUserResource.java
的构造函数:
public CustomUserResource(CustomUserRepository customUserRepository,
UserRepository userRepository, UserService userService,
PasswordEncoder passwordEncoder, DeskRepository deskRepository, EventRepository eventRepository) {
this.customUserRepository = customUserRepository;
this.userRepository = userRepository;
this.userService = userService;
this.passwordEncoder = passwordEncoder;
this.deskRepository = deskRepository;
this.eventRepository = eventRepository;
}
同样是CustomUserResourceIntTest.java
:
public CustomUserResourceIntTest(CustomUserRepository customUserRepository, UserRepository userRepository,
UserService userService, PasswordEncoder passwordEncoder,
DeskRepository deskRepository, EventRepository eventRepository) {
this.customUserRepository = customUserRepository;
this.userRepository = userRepository;
this.userService = userService;
this.passwordEncoder = passwordEncoder;
this.deskRepository = deskRepository;
this.eventRepository = eventRepository;
}
抛出错误的代码行是这样的:
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
CustomUserResource customUserResource = new CustomUserResource(customUserRepository, userRepository, userService,
passwordEncoder, deskRepository, eventRepository);
this.restCustomUserMockMvc = MockMvcBuilders.standaloneSetup(customUserResource)
.setCustomArgumentResolvers(pageableArgumentResolver)
.setControllerAdvice(exceptionTranslator)
.setMessageConverters(jacksonMessageConverter).build();
}