(一)导入junit的jar包
(二)建立Source folder 文件夹test:用于存放测试代码
(三)编写测试类即可,直接在main方法里测试,也可以采用注解的方法:
实例:
public class TeacherTestm {
private static SessionFactory sf=null;
@BeforeClass
public static void beforeClass(){
sf=new AnnotationConfiguration().configure().buildSessionFactory();
}
@Test
public void testTeacherSave(){
Teacher t = new Teacher();
t.setId(1);
t.setName("l");
t.setTitle("g");
Session session = sf.openSession();
session.beginTransaction();
session.save(t);
session.getTransaction().commit();
session.close();
}
@AfterClass
public static void close(){
sf.close();
}
}