Spring test to refer to JUnit and spring-test
<Dependency> <groupId>Junit</groupId> <Artifactid>Junit</Artifactid> <version>${junit.version}</version> <Scope>Test</Scope> </Dependency> <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-test</Artifactid> <version>${spring.version}</version> <Scope>Test</Scope> </Dependency>
Code:
Introduction of the configuration file:
Single file: @ContextConfiguration (locations = "Classpath:spring-mybatis.xml")
Multiple files: @ContextConfiguration (Locations ={"Classpath:spring-mybatis.xml", "Classpath: Application-context-provider.xml "})
ImportCom.zoe.aop.dto.*;ImportCom.zoe.aop.service.out.DeptService;ImportOrg.junit.Assert;Importorg.junit.Test;ImportOrg.junit.runner.RunWith;Importorg.springframework.beans.factory.annotation.Autowired;Importorg.springframework.test.context.ContextConfiguration;ImportOrg.springframework.test.context.junit4.SpringJUnit4ClassRunner;/*** Created by Gyoung on 2016/1/23.*/@RunWith (Springjunit4classrunner.class) @ContextConfiguration (Locations={"Classpath:spring-mybatis.xml", "Classpath:application-context-provider.xml"}) Public classdeptservertest {@AutowiredPrivateDeptservice Deptservice; @Test Public voiddeptselecttest () {Deptdto model= Deptservice.getonebyid ("2"); Assert.asserttrue (Model.getid (). Equals ("2")); } @Test Public voidupdatetest () {Deptdto model=Newdeptdto (); Model.setid ("2"); Model.setname ("111"); Deptservice.update (model); String ID=Model.getid (); } @Test Public voidpagetest () {querypage page=NewQuerypage (1,5); SERVICERESULTT<CorePageList> resultt=deptservice.getlist (page); } @Test Public voiddeletettest () {serviceresult result= Deptservice.deletebyid ("1203"); } @Test Public voidupdatedbtest () {}}
Spring's Test