Steal a lazy, the above article for testing
[http://blog.csdn.net/su20145104009/article/details/54708025]
1.spring consolidation JUnit needs to import spring-test jar packages
2. Let JUnit notify spring load configuration file
3. Allow spring container to be injected automatically
@RunWith (Springjunit4classrunner.class)//Load configuration file The tool you need to use
@ContextConfiguration ("classpath:com/scx/ Transferaccounts/applicationcontext.xml ")//spring file path public
class Test {
@Autowired//automatically inject
private Accountservice Service;
@org. Junit.test public
void Test () {
// String xmlpath= "com/scx/transferaccounts/ Applicationcontext.xml "; applicationcontext acontext=new Classpathxmlapplicationcontext (xmlpath); accountservice service= (accountservice) Acontext.getbean ("Accountserviceid");
Service.transfer ("Jack", "Rose", 1000);
}
Run Result: