ci: 编写单元测试准备
This commit is contained in:
parent
318e7dc8ac
commit
438fbb800d
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package io.metersphere.project.controller;
|
package io.metersphere.project.controller;
|
||||||
|
|
||||||
|
import io.metersphere.sdk.util.LogUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
|
@ -21,7 +22,16 @@ public class ProjectControllerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSelectAll() throws Exception {
|
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"))
|
mockMvc.perform(MockMvcRequestBuilders.get("/project/list-all"))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||||
|
|
Loading…
Reference in New Issue