晚风

博客园 首页 新随笔 联系 订阅 管理
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
public class HellowordController {
    private static final String apiHellowordUrl = "/helloword";

    private MockMvc mockMvc;

    @Autowired
    private WebApplicationContext webApplicationContext;

    @Before
    public void setUp() {
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
    }

    @Test
    public void testHelloword() throws Exception {
        MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(apiHellowordUrl )
                .param("p1", "1")
                .header("Authorization", "871d6a96ec94b4e85fbb5d77931605a")
        ).andReturn();
        log.info(mvcResult.getResponse().getContentAsString());
    }
}

  

posted on 2021-05-26 18:39  晚风  阅读(125)  评论(0编辑  收藏  举报