package com.scottwong.test;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.scottwong.bean.Employee;
import com.scottwong.service.EmployeeService;
public class EmployeeTest {
private static EmployeeService employeeService;
@BeforeClass
public static void setUpBeforeClass() throws Exception{
try {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
employeeService = (EmployeeService)ctx.getBean("employeeService");
} catch (RuntimeException e) {
e.printStackTrace();
}
}
@Test
public void save(){ //实例化spring容器 生成表结构
// employeeService.save(new Employee("张三丰",1500,3));
}
@Test
public void findById(){
Employee e =this.employeeService.findById(10);
System.out.println(e.getEmployeeName());
}
@Test
public void findAll(){
List<Employee> list = this.employeeService.findAll();
}
@Test
public void findByHQL(){
List<Employee> list = this.employeeService.findByHQL(30, "张5");
for (Employee e : list) {
System.out.println(e.getEmployeeId()+" "+e.getEmployeeName());
}
}
@Test
public void findObjectByName(){
List<Employee> list = this.employeeService.findEmployeesByemployeeName("张2");
for (Employee e : list) {
System.out.println(e.getEmployeeId()+" "+e.getEmployeeName());
}
}
}
junit spring demo
最新推荐文章于 2024-11-06 09:23:18 发布