为什么在单元测试期间我的 URL 中出现 %E2%80%8B
Why I am getting %E2%80%8B in my URL during unit testing
我正在为我的控制器编写单元测试并且获得 404 而不是 200 成功。
当我在控制台上搜索时,它显示我们 WARN log like
WARN [2021-02-12T11:53:27.711+0530] servlet.PageNotFound ||${fallback:user}|No mapping for GET /person%E2%80%8B/contacts%E2%80%8B/details
为什么映射更改为 /person%E2%80%8B/contacts%E2%80%8B/details
而不是 /person/contacts/details
测试Class
@RunWith(MockitoJUnitRunner.class)
@ActiveProfiles("test")
@SpringBootTest
public class PersonControllerTest {
@Autowired
private MockMvc mockMvc;
@InjectMocks
private PersonController personController;
@Mock
private PersonService personService;
@Before
public void setupMethod() {
mockMvc = MockMvcBuilders.standaloneSetup(personController).build();
}
@Test
public void getPersonContactDetailTest() throws Exception {
Person person = new Person();
person.setName("Test");
Mockito.when(personService.getPersonContactDetail()).thenReturn(person);
RequestBuilder rqBuilder = MockMvcRequestBuilders.get("/person/contacts/details")
.accept(MediaType.APPLICATION_JSON);
mockMvc.perform(rqBuilder).andExpect(MockMvcResultMatchers.status().isOk());
Mockito.verify(personService, times(1)).getPersonContactDetail());
}
}
%E2%80%8B
是“零宽 SPACE”字符的代码。
它可能在您不知何故的情况下被插入了。我建议完全删除定义 URL 的字符串并重新编写它。
我正在为我的控制器编写单元测试并且获得 404 而不是 200 成功。
当我在控制台上搜索时,它显示我们 WARN log like
WARN [2021-02-12T11:53:27.711+0530] servlet.PageNotFound ||${fallback:user}|No mapping for GET /person%E2%80%8B/contacts%E2%80%8B/details
为什么映射更改为 /person%E2%80%8B/contacts%E2%80%8B/details
而不是 /person/contacts/details
测试Class
@RunWith(MockitoJUnitRunner.class)
@ActiveProfiles("test")
@SpringBootTest
public class PersonControllerTest {
@Autowired
private MockMvc mockMvc;
@InjectMocks
private PersonController personController;
@Mock
private PersonService personService;
@Before
public void setupMethod() {
mockMvc = MockMvcBuilders.standaloneSetup(personController).build();
}
@Test
public void getPersonContactDetailTest() throws Exception {
Person person = new Person();
person.setName("Test");
Mockito.when(personService.getPersonContactDetail()).thenReturn(person);
RequestBuilder rqBuilder = MockMvcRequestBuilders.get("/person/contacts/details")
.accept(MediaType.APPLICATION_JSON);
mockMvc.perform(rqBuilder).andExpect(MockMvcResultMatchers.status().isOk());
Mockito.verify(personService, times(1)).getPersonContactDetail());
}
}
%E2%80%8B
是“零宽 SPACE”字符的代码。
它可能在您不知何故的情况下被插入了。我建议完全删除定义 URL 的字符串并重新编写它。