Spring+Hibnate注解编程单元测试
import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.test.context.ContextConfiguration; import org.springframework.transaction.annotation.Transactional; //使用@RunWith(SpringJUnit4ClassRunner.class),才能使测试运行于Spring测试//环境 @RunWith(SpringJUnit4ClassRunner.class) //@ContextConfiguration 注解有以下两个常用的属性: //locations:可以通过该属性手工指定 Spring 配置文件所在的位置,可以指定一个或多个 Spring 配置文件 //inheritLocations:是否要继承父测试类的 Spring 配置文件,默认为 true @ContextConfiguration(locations={"classpath:spring/spring-config-business.xml"}) public class TestRisk extends AbstractTransactionalJUnit4SpringContextTests{ @Autowired private IRiskBO bo; @Test @Transactional @rollback(false) public void Test() { Risk risk = bo.findRiskById("CW01", true); System.out.println(risk.getName()+":"+risk.getCode()); } }
相关推荐
蛰脚踝的天蝎 2020-11-10
Cocolada 2020-11-12
TuxedoLinux 2020-09-11
snowphy 2020-08-19
83540690 2020-08-16
lustdevil 2020-08-03
83417807 2020-07-19
张文倩数据库学生 2020-07-19
bobljm 2020-07-07
83417807 2020-06-28
86427019 2020-06-28
86427019 2020-06-25
zhengzf0 2020-06-21
tobecrazy 2020-06-16
宿命java 2020-06-15
83417807 2020-06-15
84284855 2020-06-11