junit-單元測試
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");
}
}
相關文章
- 測試 之Java單元測試、Android單元測試JavaAndroid
- 單元測試:單元測試中的mockMock
- [iOS單元測試系列]單元測試編碼規範iOS
- Flutter 單元測試Flutter
- Go單元測試Go
- 單元測試工具
- iOS 單元測試iOS
- 前端單元測試前端
- golang 單元測試Golang
- PHP 單元測試PHP
- phpunit單元測試PHP
- JUnit單元測試
- unittest單元測試
- Junit 單元測試.
- 單元測試真
- 前端測試:Part II (單元測試)前端
- JavaScript單元測試框架JavaScript框架
- React元件單元測試React元件
- 聊聊前端單元測試前端
- Google 單元測試框架Go框架
- 單元測試 -- mocha + chaiAI
- 單元測試與MockitoMockito
- 單元測試基礎
- Vue單元測試探索Vue
- 單元測試與 PowerMockMock
- Android - 單元測試Android
- 單元測試理解· 1
- 單元測試學習
- android單元測試Android
- [Android] 單元測試Android
- Xcode 單元測試XCode
- JUnit 4 單元測試
- Django單元測試(一)Django
- JUnit測試單元框架框架
- Junit單元測試—MavenMaven
- python 單元測試Python
- 單元測試框架 mockito框架Mockito
- 單元測試 - 測試場景記錄