码迷,mamicode.com
首页 > 编程语言 > 详细

spring单元测试

时间:2017-07-09 10:55:09      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:更新   junit4   context   set   cat   自己的   ica   work   XML   

        今天重新写了次Spring的测试,经过一番努力,还是成功的运行了的。下面记录下写作过程以及修改历程。

  首先,自己的项目有些不完整,所以中间有许多很小的bug,也在此记录下过程:

    由于自己重新生成的mybaits文件没有及时更新到项目里,所以在一开始的时候,解决这些小问题

      其次,自己没有正确处理手机号码的数据类型,从而使得在运行过程中出了一个该问题!

  下面记录下自己的测试文件代码

技术分享
 1 package com.blog.test;
 2 
 3 import org.junit.Test;
 4 import org.junit.runner.RunWith;
 5 import org.springframework.beans.factory.annotation.Autowired;
 6 import org.springframework.test.annotation.Rollback;
 7 import org.springframework.test.context.ContextConfiguration;
 8 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 9 import org.springframework.transaction.annotation.Transactional;
10 
11 import com.blog.dao.userInfoMapper;
12 import com.blog.pojo.userInfo;
13 
14 @RunWith(SpringJUnit4ClassRunner.class)
15 @ContextConfiguration({"/applicationContext.xml"})
16 public class UserInfoMappingSprintTest {
17 
18     @Autowired
19     private userInfoMapper userInfoMapper;
20     @Test
21     @Transactional
22     @Rollback(false)//用来控制事务的,当为false时不会自动回滚
23     public void test() {
24         userInfo record = new userInfo();
25         record.setUsername("dengguoqing");
26         record.setName("邓国庆");
27         record.setPassword("123456");
28         record.setSex(1);
29         record.setAge(24);
30         record.setPhonenumber(Long.parseLong("15537773239"));
31         record.setEmail("deng@163.com");
32         userInfoMapper.insert(record);
33     }
34 }
View Code

 

spring单元测试

标签:更新   junit4   context   set   cat   自己的   ica   work   XML   

原文地址:http://www.cnblogs.com/dgq-blog/p/7140512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!