Skip to content

Instantly share code, notes, and snippets.

@j-tim
Created October 26, 2020 11:59
Show Gist options
  • Select an option

  • Save j-tim/5681e6a967c98b64a3c5e869e61089a0 to your computer and use it in GitHub Desktop.

Select an option

Save j-tim/5681e6a967c98b64a3c5e869e61089a0 to your computer and use it in GitHub Desktop.
Simple Spring WebMvcTest
package com.example.azure.devops;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
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;
@WebMvcTest
class SimpleControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
public void shouldReturnHelloWorld() throws Exception {
this.mockMvc.perform(get("/")).andDo(print()).andExpect(status().isOk())
.andExpect(content().string("Hello World i'm build in Azure Pipelines!"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment