junit-单元测试
来源:互联网 发布:时时彩源码搭建流程 编辑:程序博客网 时间:2024/05/17 23:41
1.pom.xml中导入jar
2.
3.
4.
5.
6.
7.NewUserMapperTest.java
package cn.itcast.mybatis.mapper;import static org.junit.Assert.*;import java.util.ArrayList;import java.util.Date;import java.util.List;import org.junit.Before;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.github.abel533.entity.Example;import cn.itcast.mybatis.pojo.User;public class NewUserMapperTest { private NewUserMapper newUserMapper; @Before public void setUp() throws Exception { ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "classpath:spring/applicationContext*.xml"); this.newUserMapper = applicationContext.getBean(NewUserMapper.class); } @Test public void testSelectOne() { User record = new User(); // 设置查询条件 record.setuserName("zhangsan"); record.setPassword("123456"); User user = this.newUserMapper.selectOne(record); System.out.println(user); } @Test public void testSelect() { User record = new User(); // 设置查询条件 record.setuserName("zhangsan"); List<User> list = this.newUserMapper.select(record); for (User user : list) { System.out.println(user); } } @Test public void testSelectCount() { System.out.println(this.newUserMapper.selectCount(null)); } @Test public void testSelectByPrimaryKey() { User user = this.newUserMapper.selectByPrimaryKey("1"); System.out.println(user); } @Test public void testInsert() { User record = new User(); // 设置查询条件 record.setuserName("test_username_3"); //record.setAge(20); //record.setBirthday(new Date()); record.setCreated(new Date()); //record.setName("test_name_1"); //record.setPassword("123456"); record.setSex(1); record.setUpdated(new Date()); //使用所有的字段作为插入语句的字段 int count = this.newUserMapper.insert(record); System.out.println(count); System.out.println(record.getId()); } @Test public void testInsertSelective() { User record = new User(); // 设置查询条件 record.setuserName("test_username_2"); //record.setAge(20); // record.setBirthday(new Date()); record.setCreated(new Date()); // record.setName("test_name_1"); // record.setPassword("123456"); record.setSex(1); record.setUpdated(new Date()); //将不为null的字段作为插入语句的字段 int count = this.newUserMapper.insertSelective(record); System.out.println(count); System.out.println(record.getId()); } @Test public void testDelete() {// this.newUserMapper.delete(null); } @Test public void testDeleteByPrimaryKey() { System.out.println(this.newUserMapper.deleteByPrimaryKey(9L)); } @Test public void testUpdateByPrimaryKey() { fail("Not yet implemented"); } @Test public void testUpdateByPrimaryKeySelective() { User record = new User(); record.setId(1L); record.setAge(20); this.newUserMapper.updateByPrimaryKeySelective(record); } @Test public void testSelectCountByExample() { fail("Not yet implemented"); } @Test public void testDeleteByExample() { fail("Not yet implemented"); } @Test public void testSelectByExample() { Example example = new Example(User.class); List<Object> values = new ArrayList<Object>(); values.add(1L); values.add(2L); values.add(3L); example.createCriteria().andEqualTo("id", values); List<User> list = this.newUserMapper.selectByExample(example); for (User user : list) { System.out.println(user); } } @Test public void testUpdateByExampleSelective() { fail("Not yet implemented"); } @Test public void testUpdateByExample() { fail("Not yet implemented"); }}
0 0
- JUnit单元测试
- JUnit 单元测试
- 单元测试JUnit
- Junit单元测试
- Junit单元测试
- junit单元测试
- JUnit单元测试
- Junit单元测试
- JUnit单元测试
- junit单元测试
- Junit单元测试
- Junit 单元测试
- Junit单元测试
- JUnit单元测试
- JUnit单元测试
- jUnit 单元测试
- Junit单元测试
- junit 单元测试
- Java简明总结(四)
- centos 下搭建LNMP (源码安装nginx,mysql,php)
- _exit( )、exit( )、atexit( )函数比较思考
- blog_mysql后台管理
- 有没有大神帮忙精简一下,欢迎私信。
- junit-单元测试
- 题目1017:还是畅通工程(最小生成树)
- C++控制台输入输出总结
- PAT L1-016. 查验身份证
- 简单理解Socket
- 树莓派3安装笔记(1)-安装操作系统Raspbian以及安装必要软件
- xposed学习教程
- 使用Mbed通过以太网TCP接入FRDM-K64F开发板的Java / NetBeans教程
- 在Linux下的权限管理