备忘,以后有时间再写点东西吧。其实自己就没有开始写过。
blog地址:http://www.cnblogs.com/shizhongtao/p/3342174.html
//spring 配置的路径,多个用“逗号”分开
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
//固定写法,用junit4
@RunWith(SpringJUnit4ClassRunner.class)
//加入事物时候的配值,“txmanage”事物管理器的名字,默认回滚,
@TransactionConfiguration(transactionManager="txManager",defaultRollback=true)
//为所有方法加入事物,也可以对各个方法分别定义,此处不写
@Transactional
public class MessageAccessoryTest
{
@Resource(name="messageAccessoryDao" )
private MessageAccessoryDao messageAccessoryDao;
@Resource(name="messageDao")
private MessageDao messageDao;
//不会滚,即插入数据库
@Rollback(false)
@Test
public void testAccessorySave(){
Accessory accessory=new Accessory();
accessory.setAccName("attachment2");
Message m= messageDao.getMessageById("402883c73eb043c0013eb043c3dd0000");
accessory.setMessage(m);
String id= messageAccessoryDao.saveAccessory(accessory);
System.out.println(id);
Assert.assertTrue(id.length()==32);
}