A test case for Spring boot

Source: Internet
Author: User
Tags assert

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.