BE Study 7th
Let's take a look at test codes.
package com.sivalabs.techbuzz.posts.web.controllers;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import com.sivalabs.techbuzz.common.AbstractIntegrationTest;
import org.junit.jupiter.api.Test;
class HomeControllerTest extends AbstractIntegrationTest {
@Test
void shouldHomePageWithCategoriesList() throws Exception {
mockMvc.perform(get("/"))
.andExpect(status().isOk())
.andExpect(view().name("posts/home"))
.andExpect(model().attributeExists("categories"));
}
}
guess the mockMvc gets "/" which is home and checks if status() is Ok and view()'s file name is "post/home" and model has attribute named "categories".
댓글
댓글 쓰기