spring unit test
pom.xmlorg.springframework.boot spring-test test
XXTest.java
@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = "classpath:applicationContext.xml")//@ContextConfiguration(classes = {xxxxxx.class}public class UserDaoTest extends AbstractJUnit4SpringContextTests { @Resource private UserDaoInterface userDao; @Test public void saveTest() { .... }}
spring test with mock
xxxTest.java
@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration("file:src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml")@WebAppConfiguration(value = src/main/webapp)public class AppTests { private MockMvc mockMvc; @Autowired protected WebApplicationContext wac; @Before public void setup() { this.mockMvc = webAppContextSetup(this.wac).build(); } @Test public void simple() throws Exception { mockMvc.perform(post("/mytest")) .andExpect(view().name("index2")) .andDo(print()).andExpect(status().isOk()); }}