spring+junit測試

主要須要JUnit 4 、spring test包java

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:ApplicationContext.xml"})
public class Test {
    @Autowired
    Dao dao;
    
    @Test
    public void testEmployee(){
        
        assertEquals("zhangsan",dao.getUserName());
    }

}

@RunWith    junit4裏用它來作junit加載器spring

@ContextConfiguration   主要用來加載spring的配置文件路徑:是一個字符串數組,能夠加載多個spring配置文件數組

相關文章
相關標籤/搜索