SpringBoot单元测试

直接上代码

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

@AutoConfigureMockMvc
@RunWith(SpringRunner.class)
@SpringBootTest
public class WorkerControllerTest {

    @Autowired
    private MockMvc mockMvc;

    @Test
    public void updateStatus() throws Exception {
        mockMvc.perform(RestDocumentationRequestBuilders.post("/update")
                .param("status", "0")
        );
    }

}

你可能感兴趣的:(工作记录)