포스트

Spring boot test

@RunWith(SpringRunner.class)
@Profile("local")
@SpringBootTest
@Transactional
public class CreateTest {

  @Autowired
  private WebApplicationContext wac;

  private MockMvc mockMvc;

  private ObjectMapper objectMapper = new ObjectMapper();

  @Before
  public void before() throws Exception {
    mockMvc = MockMvcBuilders
        .webAppContextSetup(this.wac)
        .alwaysDo(MockMvcResultHandlers.print())
        .build();
  }

  @Test
  public void 등록_성공() throws Exception {

    CreateRequest request = new CreateRequest();
    List list = new ArrayList<>();
    list.add(request);

    mockMvc.perform(
        post("/v2/rest/products")
            .contentType(MediaType.APPLICATION_JSON_UTF8)
            .content(objectMapper.writeValueAsString(list))
    )
        .andExpect(status().isBadRequest())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
  }
}

MockMvc 를 이용한 테스트, 이후에 쭉 작성할 예정

​

​

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.