PackageTk.mybatis.springboot.mapper;ImportOrg.junit.Assert;Importorg.junit.Test;ImportOrg.junit.runner.RunWith;ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;Importorg.springframework.beans.factory.annotation.Autowired;Importorg.springframework.boot.test.SpringApplicationConfiguration;ImportOrg.springframework.test.annotation.Rollback;ImportOrg.springframework.test.context.junit4.SpringJUnit4ClassRunner;Importorg.springframework.test.context.web.WebAppConfiguration;Importorg.springframework.transaction.annotation.Transactional;Importtk.mybatis.springboot.Application;ImportTk.mybatis.springboot.model.City2;Importjava.util.ArrayList;Importjava.util.List;/** * @authorLiuzh *@since2016-03-06 17:42*/@RunWith (Springjunit4classrunner.class) @WebAppConfiguration @transactional@springapplicationconfiguration (application.class) Public classMybatis331test {PrivateLogger Logger =Loggerfactory.getlogger (GetClass ()); @AutowiredPrivateMybatis331mapper Mapper; @Test @Rollback Public voidtestinsertlist () {List<City2> city2list =NewArraylist<city2>(); City2list.add (NewCity2 ("Shijiazhuang", "Hebei")); City2list.add (NewCity2 ("Handan", "Hebei")); City2list.add (NewCity2 ("Qinhuangdao", "Hebei")); Assert.assertequals (3, Mapper.insertcities (city2list)); for(City2 c2:city2list) {logger.info (c2.tostring ()); Assert.assertnotnull (C2.getid ()); }} @Test Public voidTestselectbyid () {City2 city2= Mapper.selectbycityid (1); Logger.info (City2.tostring ()); Assert.assertnotnull (City2); Assert.assertnotnull (City2.getcityname ()); Assert.assertnotnull (City2.getcitystate ()); } @Test Public voidTestselectall () {List<City2> city2list =Mapper.selectall (); for(City2 c2:city2list) {logger.info (c2.tostring ()); Assert.assertnotnull (C2); Assert.assertnotnull (C2.getcityname ()); Assert.assertnotnull (C2.getcitystate ()); } }}
How to load and configure For Integration tests
Similar to the standard contextconfiguration but uses Spring Boot ' s SpringApplicationContextLoader.Author:Dave syersee Al So:springapplicationcontextloader
Http://docs.spring.io/spring-boot/docs/1.1.x/api/org/springframework/boot/test/SpringApplicationConfiguration.html
A test case for Spring boot