📄 personservicetest.java
字号:
package junit.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 cn.itcast.bean.Person;
import cn.itcast.service.PersonService;
public class PersonServiceTest {
private static PersonService personService;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
try{
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("beans.xml");
personService=(PersonService)applicationContext.getBean("personService");
}catch(RuntimeException e){
e.printStackTrace();
}
}
@Test
public void testSave() {
personService.save(new Person("ping"));
}
@Test
public void testUpdate() {
Person person=personService.getPerson(3);
person.setName("hong");
personService.update(person);
}
@Test
public void testGetPerson() {
Person person=personService.getPerson(1);
System.out.print(person.getName());
}
@Test
public void testDelete() {
personService.delete(1);
}
@Test
public void testGetPersons() {
List<Person> persons=personService.getPersons();
for(Person p:persons){
System.out.println(p.getName());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -