码迷,mamicode.com
首页 > 其他好文 > 详细

Junit 简单使用

时间:2016-03-13 00:51:08      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

package com.ejokovic.test; 

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.ejokovic.Util.SqlSessionFactoryUtil;
import com.ejokovic.dao.StudentMapper;
import com.ejokovic.model.Student;

/** 
 * @author 作者 E-mail: ejokovic@aliyun.com
 * @version 创建时间:2016年3月12日 下午11:22:27 
 * 类说明  Junit测试单元
 */
public class StudentTest2 {

	private static Logger logger = Logger.getLogger(StudentTest2.class);
	
	private SqlSession sqlSession = null;
	private StudentMapper studentMapper = null;
	
	// 调用testAdd方法之前执行
	@Before
	public void setUp() throws Exception {
		// 每次获取一个新的session
		sqlSession = SqlSessionFactoryUtil.openSession();
		studentMapper = sqlSession.getMapper(StudentMapper.class);
	}

	// 调用testAdd方法之后执行
	@After
	public void tearDown() throws Exception {
		// 使用完成后 进行关闭
		sqlSession.close();
	}

	@Test
	public void testAdd() {
		logger.info("添加学生");
		Student student = new Student("王五",13);
		int res = studentMapper.add(student);
		if(res>0)
			logger.info("添加成功");
	}

}

 

Junit 简单使用

标签:

原文地址:http://www.cnblogs.com/ejokovic/p/5271032.html

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