编写单个controller的测试用例

This commit is contained in:
EightMonth
2025-04-07 15:59:46 +08:00
parent bb4cdf93b1
commit 70a1f0b7db
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,37 @@
package org.jeecg.modules.system.test;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.modules.base.service.BaseCommonService;
import org.jeecg.modules.demo.mock.MockController;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
/**
* 单个controller测试
* @date 2025/4/7 11:21
*/
@WebMvcTest(value = MockController.class)
public class MockControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private BaseCommonService baseCommonService;
@MockBean
private JeecgBaseConfig jeecgBaseConfig;
@Test
public void testSave() throws Exception {
mockMvc.perform(get("/mock/api/json/area"))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk());
}
}