Created
June 1, 2019 04:45
-
-
Save donchan922/0af86769544bdb4221f566a778c4e010 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DemoControllerTest { | |
// Spring MVCのモック | |
private MockMvc mockMvc; | |
@BeforeEach | |
void setup() { | |
// Spring MVCのモックを設定する | |
this.mockMvc = MockMvcBuilders.standaloneSetup(new DemoController()).build(); | |
} | |
@Test | |
void GETでアクセスする() throws Exception { | |
// GETで「/」にアクセスする | |
mockMvc.perform(MockMvcRequestBuilders.get("/")) | |
// レスポンスのステータスコードが200であることを検証する | |
.andExpect(status().isOk()) | |
// レスポンスボディが「Hello World」であることを検証する | |
.andExpect(content().string("Hello World")); | |
} | |
@Test | |
void POSTでアクセスする() throws Exception { | |
// POSTで「/」にアクセスする | |
mockMvc.perform(MockMvcRequestBuilders.post("/")) | |
// レスポンスのステータスコードが405(METHOD_NOT_ALLOWED)であることを検証する | |
.andExpect(status().isMethodNotAllowed()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment