ci: 编写单元测试准备

This commit is contained in:
CaptainB 2023-04-26 14:41:20 +08:00
parent 318e7dc8ac
commit 438fbb800d
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,41 @@
package io.metersphere.project.controller;
import io.metersphere.sdk.util.LogUtils;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@AutoConfigureMockMvc
public class ProjectApplicationControllerTests {
@Resource
private MockMvc mockMvc;
@Test
public void testSelectAll() throws Exception {
LogUtils.info("testSelectAll");
mockMvc.perform(MockMvcRequestBuilders.get("/project/list-all"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
// .andExpect(jsonPath("$.person.name").value("Jason"))
.andDo(print());
}
@Test
public void testSelectAll2() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/project/list-all"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
// .andExpect(jsonPath("$.person.name").value("Jason"))
.andDo(print());
}
}

View File

@ -1,5 +1,6 @@
package io.metersphere.project.controller;
import io.metersphere.sdk.util.LogUtils;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@ -21,7 +22,16 @@ public class ProjectControllerTests {
@Test
public void testSelectAll() throws Exception {
LogUtils.info("testSelectAll");
mockMvc.perform(MockMvcRequestBuilders.get("/project/list-all"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
// .andExpect(jsonPath("$.person.name").value("Jason"))
.andDo(print());
}
@Test
public void testSelectAll2() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/project/list-all"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))