import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
import com.tripb2b.receive.operator.entity.TbReceiveGuestMemberUser;
import com.tripb2b.receive.operator.service.OperatorImService;
@ContextConfiguration(
locations = { //spring的配置文件
"classpath*:/applicationContext.xml",
"classpath*:/applicationContext-quartz.xml"
}
)
@RunWith(SpringJUnit4ClassRunner.class)//用于配置spring中测试的环境
@Transactional//注解事务,在applicationContext。xml的<tx:annotation-driven>
@TransactionConfiguration(
transactionManager = "transactionManager",// transactionManager = "transactionManager" 后面的transactionManager必须是applicationContext。xml中配置的事务管理器配置
defaultRollback = true// defaultRollback=true,数据会真的传入数据库,但是事务结束后,会回滚数据。这个不是完全意义的无污染,因为如果主键是自增的,那么,下次传入数据,会发现主键不是连续的。
// 即:主键是自增的,测试前,主键是9,测试插入一次,测试后,再次插入,主键是11(不是10)
// 若defaultRollback=false,则数据正常插入数据库
)
public class TestM {
@Autowired
public OperatorImService operatorImService;// spring的bean注解方式注入
@Test
public void t1(){
System.out.println("方法执行之前 begin");
List<TbReceiveGuestMemberUser> l = operatorImService.queryMemberUsers(10, null, null, null);
System.out.println(l.size());
System.out.println("方法执行完毕 over");
}
}