我目前正在开发一个Spring项目,我想编写一些测试。不幸的是,我不知道如何传递所需的数组。
Get Request可以正常工作...这是我的代码:
MainControllerTest.java
public function br_number_search(Request $request)
{
$query = $request['query'];
return $variants = Variant::with('case_bottles', 'product')
->where('br_no', 'LIKE', "%$query%")
->get();
}
MainController.java
private MockMvc mockMvc;
@InjectMocks
private MainController controller;
@Before
public void setUp() throws Exception {
mockMvc = MockMvcBuilders.standaloneSetup(controller)
.build();
}
@Test
public void resetAll() throws Exception {
String[] players = new String[] {"Player 1", "Player 2"};
mockMvc.perform(
MockMvcRequestBuilders.get("http://localhost:8443/api/reset")
)
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string("false"));
mockMvc.perform(
MockMvcRequestBuilders.post("http://localhost:8443/api/player").content(players)
);
}
谢谢您的帮助!