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
- 單元測試,只是測試嗎?
- 單元測試-【轉】論單元測試的重要性
- SpringBoot單元測試Spring Boot
- python 單元測試Python
- iOS 單元測試iOS
- Flutter 單元測試Flutter
- 單元測試 Convey
- 單元測試真
- golang單元測試Golang
- 單元測試工具
- 前端單元測試前端
- 十五、單元測試
- Go單元測試Go
- 聊聊單元測試
- 前端測試:Part II (單元測試)前端
- JavaScript單元測試框架JavaScript框架
- 單元測試 -- mocha + chaiAI
- React元件單元測試React元件
- Spring Boot 單元測試Spring Boot
- Vue單元測試探索Vue
- Google 單元測試框架Go框架
- 單元測試與MockitoMockito
- Junit單元測試—MavenMaven
- 單元測試框架 mockito框架Mockito
- 單元測試?即刻搞定!
- Source Generator 單元測試
- 聊聊前端單元測試前端
- 單元測試基礎
- Go 單元測試之mock介面測試GoMock
- 測試氣味-整潔單元測試
- 單元測試 - 測試場景記錄
- 單元測試-一份如何寫好單元測試的參考
- 測試開發之單元測試-禪道結合ZTF驅動單元測試執行
- 測試夜點心:單元測試測什麼
- Vue 應用單元測試的策略與實踐 04 - Vuex 單元測試Vue
- 程式碼重構與單元測試——重構1的單元測試(四)
- Flutter 學習之路 - 測試(單元測試,Widget 測試,整合測試)Flutter