@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(
classes = {App.class}
)
@WebAppConfiguration
public class SpringbootTest {
private static final Log log = LogFactory.getLog(SpringbootTest.class);
@Autowired
private UserPojo userPojo;
private MockMvc mvc;
public SpringbootTest() {
}
@Before
public void setUp() throws Exception {
this.mvc = MockMvcBuilders.standaloneSetup(new Object[]{new HelloController()}).build();
}
@Test
public void getHello() throws Exception {
this.mvc.perform(MockMvcRequestBuilders.get("/first/hello1", new Object[0]).accept(new MediaType[]{MediaType.APPLICATION_JSON})).andExpect(MockMvcResultMatchers.status().is(404));
}
@Test
public void userInfo() {
Assert.assertEquals(this.userPojo.getName(), "songhuanhuan");
Assert.assertEquals(this.userPojo.getSex(), "女");
log.info("日志");
}
}
转载于:https://www.cnblogs.com/metu/p/9219445.html