Junit 單元測試.
package com.rs.common.core.dao.test;
import java.util.Locale;
import org.junit.Test;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
import com.rs.common.core.dao.UserDao;
import com.rs.common.core.dao.exception.DatabaseException;
import com.rs.common.core.model.User;
import com.rs.common.core.service.exception.UserExistsException;
import com.rs.common.core.service.exception.UserServiceException;
public class TestUserDao extends AbstractTransactionalDataSourceSpringContextTests {
//重寫getConfigLocations方法;
protected String[] getConfigLocations() {
return new String[] { "spring-config.xml" };
}
//注入UserDao;
private UserDao userDao;
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
/**
* 根據User_id查詢
*/
@Test
public void testLoadbByUserID() {
//this.testCreate(); // insert user
User user = null;
try {
user = userDao.load("11000002");
} catch (DatabaseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("ID:" + user.getId());
System.out.println("UserID:" + user.getUserId());
System.out.println("First Name:" + user.getFirstName());
System.out.println("Last Name:" + user.getLastName());
System.out.println("Email:" + user.getEmail());
System.out.println("Age:" + user.getAge());
}
@Test
public void testUpdateUserById(){
try {
//查詢使用者;
User user = userDao.queryUserById("11000001");
System.out.println(user.getAge());
//設定年齡;
user.setAge(99);
//執行更新;
userDao.update(user);
//輸出結果;
System.out.println(userDao.queryUserById("11000001").getAge());
} catch (DatabaseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("DatabaseException:"+e.toString());
}
}
public void testAddUser() {
System.out.println("更新使用者");
User u = null;
try {
u = userDao.queryUserById("11000001");
System.out.println("更新之前:"+u.getAge());
u.setAge(55);
userDao.update(u);
System.out.println("更新之後:"+userDao.queryUserById("11000001").getAge());
} catch (DatabaseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
User user = new User();
user.setUserId("12000009");
user.setGender("F");
user.setAge(20);
user.setDisplayLanguageLocal(Locale.ENGLISH);
user.setStatus("Active");
user.setEmail("haitao7290783@126.com");
user.setPassword("password");
try {
userDao.add(user);
} catch (DatabaseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("新增成功!");
}
}
相關文章
- Junit單元測試—MavenMaven
- 使用JUnit進行單元測試
- 實驗三junit單元測試
- 1.13-java單元測試junitJava
- Java Junit單元測試(入門必看篇)Java
- Java單元測試之JUnit 5快速上手Java
- SpringBoot與單元測試JUnit的結合Spring Boot
- Spring單元測試教程(JUnit5+Mockito)SpringMockito
- JUnit+Mockito單元測試之打樁when().thenReturn();Mockito
- Springboot整合JUnit5優雅進行單元測試Spring Boot
- Java新一代單元測試框架JUnit5速覽Java框架
- 測試 之Java單元測試、Android單元測試JavaAndroid
- 單元測試:單元測試中的mockMock
- springboot junit測試Spring Boot
- Junit 4 測試方法
- 【JUnit測試】總結
- 單元測試,只是測試嗎?
- 單元測試-【轉】論單元測試的重要性
- SpringBoot單元測試Spring Boot
- python 單元測試Python
- iOS 單元測試iOS
- Flutter 單元測試Flutter
- 單元測試 Convey
- 單元測試真
- golang單元測試Golang
- 單元測試工具
- 前端單元測試前端
- 十五、單元測試
- Go單元測試Go
- 聊聊單元測試
- spring1.2+hibernate3.0+junit3.8+jdk1.4的單元測試異常解決方法SpringJDK
- 解決JUnit單元測試時出現的Java.lang.Exception: No runnable methods問題JavaException
- 前端測試:Part II (單元測試)前端
- junit測試工具運用
- SpringBoot整合Junit單元測試找不到bean報錯:expected at least 1 bean which qualifies as autowire candidateSpring BootBeanAST
- JavaScript單元測試框架JavaScript框架
- 單元測試 -- mocha + chaiAI
- React元件單元測試React元件
- Spring Boot 單元測試Spring Boot