Junit

首先导入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(); } }


 也可以

只是模拟创建表出来

@Test
	public void one() {
		new SchemaExport(new AnnotationConfiguration().configure()).create(true, false);
	}

第一个true控制是否在后台打印sql语句

第二个true控制是否在数据库创建
 

 

右键,run as + junit test

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值