Created
February 7, 2017 06:12
-
-
Save gokman/50f80e9017b656d9478d2aae85b2a468 to your computer and use it in GitHub Desktop.
Spring Boot Controller Unit Test
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
@SpringBootTest(classes = XXXApplication.class) //if we change Application.class we must declare here what the application main class is | |
@RunWith(SpringRunner.class) | |
public class UserControllerTests { | |
private MockMvc mockMvc; | |
@Autowired | |
WebApplicationContext webApplicationContext; | |
@Before | |
public void setup() { | |
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build(); | |
} | |
@Test | |
public void createUseerWithBadCredentialsWillReturnBadRequest() throws Exception{ | |
User user = new User(); | |
this.mockMvc.perform(post("/v1/user") | |
.accept(MediaType.APPLICATION_JSON) | |
.contentType(MediaType.APPLICATION_JSON) | |
.content(new ObjectMapper().writeValueAsString(customer))) | |
.andExpect(status().isBadRequest()) | |
.andExpect(content().string(containsString("check your credentials"))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment