Junit
来源:互联网 发布:今日eia数据 编辑:程序博客网 时间:2024/06/04 00:52
首先导入Junit4.7的包
接着在工程底下新建个与src同级的一个专门测试用的文件夹new一个 source folder
在该文件夹下新建个包和test类
把要测试的内容写在test类里
package com.sl.test;
import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.cfg.AnnotationConfiguration;import org.hibernate.cfg.Configuration;import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;
import com.qi.pojo.teacher;
public class testTeacher { private static SessionFactory factory=null; private static Session session=null ; @BeforeClass public static void before(){ Configuration config = new AnnotationConfiguration(); config.configure(); factory = config.buildSessionFactory(); } @Test public void testSave() { System.out.println("begin"); teacher t = new teacher(1, "xxx", 17); session = factory.openSession(); session.beginTransaction(); session.save(t); session.getTransaction().commit(); System.out.println("save ok"); } @AfterClass public static void after(){ session.close(); }}
也可以
只是模拟创建表出来
@Testpublic void one() {new SchemaExport(new AnnotationConfiguration().configure()).create(true, false);}
第一个true控制是否在后台打印sql语句
第二个true控制是否在数据库创建
右键,run as + junit test
- JUNIT
- junit
- Junit
- JUnit
- JUnit
- JUnit
- JUNIT
- junit
- Junit
- JUnit
- Junit
- JUnit
- Junit
- Junit
- JUnit
- junit
- junit
- JUnit
- sql2000 SP4 判断
- 如何知道一个nat后面的机器的公网ip是什么
- 文件操作 写文件
- 控件的几何排布---QT
- DWZ (JUI) 教程 NavTab Dialog Title 设置问题
- Junit
- 小米2在Eclipse 调试,要注意下列步骤。
- android在物联网的应用
- 关于电容串联并联的问题
- 类图 关系
- Socket编程基础(一)
- struts2必备jar包(2.1.6版本)
- 如何进行ibatis动态多条件组合查询以及模糊查询
- pyodbc下连接mssql的便用示例